Bryan R Harris wrote:
> 
>>D. Bolliger wrote:
>>>Mug am Mittwoch, 25. Oktober 2006 13:12:
>>>
>>>>I don't know if that anyway I can know what should I pass back
>>>>from right hand side to left hand side, like :
>>>>
>>>>my $x = qw/a b c d e / ; # so I have $x = 5
>>>The list on the right hand side is evaluated in scalar context, and that
>>>delivers the number of entries in the list.
>>No it doesn't:
>>
>>$ perl -le' $x = qw/ a b c d e /; print $x'
>>e
> 
> 
> Why?  That doesn't make sense to me.
> 
> 1) perl -le '($x) = qw/a b c d e/; print $x'
> a
> 
> 2) perl -le '$x = qw/a b c d e/; print $x'
> e
> 
> 3) perl -le '$x = ( qw/a b c d e/ ); print $x'
> e
> 
> 4) perl -le '@a = qw/a b c d e/; $x = @a; print $x'
> 5
> 
> 
> Why are (2) and (4) different?

In (2) you are assigning to a scalar (scalar context) and in (4) you are
assigning to an array (list context) and then assigning the number of elements
in the array to $x (an array in scalar context evaluates to the number of
elements in that array.)


> Or better what is (2) doing?

Read up on the comma operator in perlop (and I know there are no literal
commas in (2) but qw/a b c d e/ behaves exactly the same as ('a', 'b', 'c',
'd', 'e').)

perldoc perlop


> Why doesn't (3) work?

It does work.  It just doesn't work the way you seem to think it should work.
 The parentheses are used for precedence and since the expression qw/a b c d
e/ is unambiguous the parentheses are superfluous.




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to