OK, my interpretation: the outer parens enclose to the params passed to scalar(). Both lines evaluate the result of the assignment in scalar context.
as you can see there is no measurable difference between (),(2),(1,2)DB<36> print scalar (($a)=5) 1 # Number of elements in list DB<37> print scalar ($a=5) 5 # value of $a
whats notable is that ($a) is evaluated like a literal array!DB<41> print scalar (@a=(5,6)) 2 DB<42> print scalar (@a=(6)) 1 DB<43> print scalar (@a=()) 0
AFAIR what one expect as "the scalar of a list" should be the last element and only the scalar of an array is the number of elements.DB<49> print scalar ( ($a)=(5,6,7) ) 3 DB<50> print scalar ( ($a,$b)=(5,6,7) ) 3 DB<51> print scalar ( ()=(5,6,7) ) 3
So the results prooves once again how problematic it is in perl5 to see the difference between arrays and lists!
Maybe as a rule of thumb: Lists are immutable, so what looks like "a list at the LHS" has to be an array !
Cheers Rolf
In reply to Re^14: chopping a string into slices - is there a more elegant way to do it?
by LanX
in thread chopping a string into slices - is there a more elegant way to do it?
by rovf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |