Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: each %hash: scalar context of list (undef, undef) is false

by ikegami (Patriarch)
on Nov 22, 2014 at 20:09 UTC ( [id://1108124]=note: print w/replies, xml ) Need Help??


in reply to each %hash: scalar context of list (undef, undef) is false

In

while ( ($key, $value) = each %hash ) { ... }

The operator the while is evaluating is the list assignment operator. ($key, $value) and each %hash are the operands to the list assignment operator. It's as if you have list_assign(list(lexical_sv('key'), lexical_sv('value')), each(lexical_hv('hash'))). As you can see, the list assignment operator is what is in scalar context, not ($key, $value). To see what the list assignment operator returns in scalar context, see Mini-Tutorial: Scalar vs List Assignment Operator, but it's easy to figure out.

>perl -E"say scalar( ($x,$y)=() )" 0 >perl -E"say scalar( ($x,$y)=(undef) )" 1 >perl -E"say scalar( ($x,$y)=(undef,undef) )" 2 >perl -E"say scalar( ($x,$y)=(undef,undef,undef) )" 3

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found