On Jul 10, bob ackerman said:
>and, as someone pointed out, this does work:
>$x = ['abc','def','ghi'];
>print @$x[2]."\n"; # prints 'ghi'
>
>but i couldn't tell you how perl reads this, except to say that '@$x'
>dereferences and then '[2]' gets the array element.
>but i don't know why a '$' isn't needed to tell perl you want the scalar
>value of that element.
Because Perl sees this:
@{ $x }[2]
which is an array slice (of an array reference) of one element. The $x is
merely taking the place of a name.
@FOO[2]
is a single-element array slice; replace FOO with $x, and you get
@$x[2]
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]