Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: list context (iterators)

by LanX (Chancellor)
on Dec 07, 2010 at 00:12 UTC ( #875713=note: print w/ replies, xml ) Need Help??

in reply to list context

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!

Comment on Re: list context (iterators)
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://875713]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2015-11-28 02:53 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (737 votes), past polls