SPUG: basic array question
Mathew D. Watson
matw at eclipse-optics.com
Tue May 10 14:40:31 PDT 2005
I'm studying some perl fundamentals, and I'm cooking up examples
convince myself that I understand (or don't) what perl is doing. Here's
an "I don't" that I'm hoping you folks can explain.
#!/usr/bin/perl -w # line 1
@a = (@x = (1, 2, 3), $y = 'a', 9); # line 2
$a = (@x = (1, 2, 3), $y = 'a', 9); # line 3
$b = @a; # line 4
Please correct me if I write something wrong.
@a on line 2 has the value (1, 2, 3, 'a', 9), which makes sense. The
right hand side is evaluated in a list context because the variable on
the left hand side is an array.
$a on line 3 has the value 9, which is the last element of the array on
the rhs. What is the rule at work here? Is the rhs considered an array?
I'm not sure what context the rhs is evaluated in.
$b on line 4 has the value 5, the number of elements in @a, which is
what I thought might happen with $a on line 2. @a is evaluated in a
scalar context because the lhs is a scalar. Why aren't $a and $b the same?
Mat
More information about the spug-list
mailing list