in reply to Re^13: chopping a string into slices - is there a more elegant way to do it?
in thread chopping a string into slices - is there a more elegant way to do it?

> He hasn't had a chance to explain how that accounts for the difference in the output of scalar(($a)=5) and scalar($a=5)

OK, my interpretation: the outer parens enclose to the params passed to scalar(). Both lines evaluate the result of the assignment in scalar context.

DB<36> print scalar (($a)=5) 1 # Number of elements in list DB<37> print scalar ($a=5) 5 # value of $a
as you can see there is no measurable difference between (),(2),(1,2)
DB<41> print scalar (@a=(5,6)) 2 DB<42> print scalar (@a=(6)) 1 DB<43> print scalar (@a=()) 0
whats notable is that ($a) is evaluated like a literal array!
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
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.

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