On Wednesday, July 10, 2002, at 09:05  AM, Jeff 'japhy' Pinyan wrote:

> 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]
>

but i repeat:
you get a warning with @x[2] if 'x' is an array,
but no warning with @$x[2] where 'x' is an array ref.
so perl isn't handling quite the same.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to