For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > July 2004 > what is this ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author what is this ?
George Bouras

2004-07-29, 3:55 am

normal array slice
@array[0,1,23,100]

what is this ?
@array["hello1","hello2", ...];


Joe Smith

2004-07-29, 3:55 am

George Bouras wrote:

> normal array slice
> @array[0,1,23,100]
>
> what is this ?
> @array["hello1","hello2", ...];


Since "hello1" is zero when evaluated in numeric context, it is the same as
@array[0,0] which is ($array[0],$array[0]).

Now, if you were using braces {} instead of brackets [], the answer would
be different.
-Joe
gnari

2004-07-29, 3:55 am

"George Bouras" <gravitalsun.ANTISPAM@yahoo.com> wrote in message
news:ce50mn$2b2k$1@ulysses.noc.ntua.gr...
> normal array slice
> @array[0,1,23,100]
>
> what is this ?
> @array["hello1","hello2", ...];


you probably mean this:
@array{"hello1","hello2", ...};

in that case, it is a hash slice, equivalent to:
($array{'hello1'},$array{'hello2'},...);

gnari




George Bouras

2004-07-29, 3:55 am

I read it at POE Perl module documentation.

sub handler_start
{
my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION];
....
}



I think it must be something similar to

use constant A=>1;
use constant B=>7;
use constant C=>9;

f1( qw/a b c d e f g h i j k l m n o p q/ );

sub f1
{
my ($a,$b,$c) = @_[A,B,C];
print "$a $b $c\n";
}





George Bouras

2004-07-29, 3:55 am

I read it at POE samples and documentation.

sub handler_start
{
my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION];
....
}



I think it must be something similar to

use constant A=>1;
use constant B=>7;
use constant C=>9;

f1( qw/a b c d e f g h i j k l m n o p q/ );

sub f1
{
my ($a,$b,$c) = @_[A,B,C];
print "$a $b $c\n";
}




Matt Garrish

2004-07-29, 3:55 am


"George Bouras" <gravitalsun.ANTISPAM@yahoo.com> wrote in message
news:ce56dv$2nft$1@ulysses.noc.ntua.gr...
> I read it at POE Perl module documentation.
>
> sub handler_start
> {
> my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION];
> ...
> }
>
>
>
> I think it must be something similar to
>
> use constant A=>1;
> use constant B=>7;
> use constant C=>9;
>
> f1( qw/a b c d e f g h i j k l m n o p q/ );
>
> sub f1
> {
> my ($a,$b,$c) = @_[A,B,C];
> print "$a $b $c\n";
> }
>


See POE::Session for more information. In essence you are correct about them
being constants:

Each session maintains its unique runtime context. Sessions pass their
contexts on to their states through a series of standard parameters. These
parameters tell each state about its Kernel, its Session, itself, and the
events that invoke it.

State parameters' offsets into @_ are never used directly. Instead they're
referenced by symbolic constant. This lets POE to change their order without
breaking programs, since the constants will always be correct.

Matt


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com