in my $x = 10; the = is a scalar assignment which returns the assigned scalar

in my ($y) = 10; the = is a list assignment which returns the number of assigned elements╣

That's a crucial trick for iterators, where returned elements might be false (like 0 , '' or undef).


while ( ($x) = iterator() ) { ... }
will work as long as anything (i.e. no empty list) is returned, while
while ( $x = iterator() ) { ... }
can break if you don't use special magics like "0 but true".

Cheers Rolf


1) in scalar context!

In reply to Re: list context (iterators) by LanX
in thread list context by 7stud

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":