On Wednesday, July 10, 2002, at 09:29  AM, George Schlossnagle wrote:

>> and, as someone pointed out, this does work:
>> $x = ['abc','def','ghi'];
>> print @$x[2]."\n";       # prints 'ghi'
>
>
> Am I alone in thinking that  $x->[2]  is much more readable that @$x[2] 
> or $$x[2]?

i was only saying that it was allowable. not that is desirable to do it 
that way. i agree with your preference.

>
>>
>> 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.
>
> @$x[2] works the same way that if you have
>
> @b = ('abc','def','ghi');
> print "@b[2] == $b[2]\n";
>
> @b[2] is an array slice with a single element (which strangely seems to 
> get auto-cast as a scalar).
>

except i get a warning on this use:
@y = ('a','b','c');
print @y[2]."\n";

 >Scalar value @y[2] better written as $y[2] at ./tst line 4.
 >c

i don't get that warning when it is an array ref.


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

Reply via email to