>Actually, you're dealing with a well-documented, but poorly understood
>feature. Try this:
>
>my $number_of_pets = ('dog','cat','iguana');
>print $number_of_pets;
>
>my @pets = ('dog','cat','iguana');
>$number_of_pets = @pets;
>print $number_of_pets;
>
>$number_of_pets = ('dog','cat',@pets);
>print $number_of_pets;
>
>@number_of_pets = ('dog','cat',@pets);
>print scalar @number_of_pets;
>
>The first print results in 'iguana' and the second and third print
>statements print 3. The fourth
>print display a 5.
>
>What's going on here is subtle. Putting parens around those scalars
>creates a "list literal".
>When a list literal is accessed in scalar context, it evaluates each item
>in scalar context and
>returns the value of the final element. Since, in the third example, the
>array is the third
>element, it's evaluated in scalar context, as expected.
>
>So why do the third and fourth examples have different outputs? Because
>lists are not arrays and
>do not behave as such.
Interestingly, saying
print my $number_of_elems = qw(a b c d);
outputs 4 and not d.
does qw turn the list into an array?
Peter Cline
Inet Developer
New York Times Digital