Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
No such thing as a small change
 
PerlMonks  

Re^2: Can't understand function returning undefs

by rg0now (Chaplain)
on Sep 24, 2010 at 21:50 UTC ( #861899=note: print w/ replies, xml ) Need Help??


in reply to Re: Can't understand function returning undefs
in thread Can't understand function returning undefs

Here is what drives me crazy:

if(undef, undef){ print "OK1\n"; } if( (undef, undef) ){ print "OK2\n"; } my @a = (undef, undef); if(@a){ print "OK3\n"; }
This prints OK3. According to the above, it should also print OK2 because (undef, undef) is a list of two elements that evaluates to 2 in scalar context. Still, it doesn't.


Comment on Re^2: Can't understand function returning undefs
Select or Download Code
Re^3: Can't understand function returning undefs
by JavaFan (Canon) on Sep 24, 2010 at 21:57 UTC
    There are no lists in scalar context! It's SCALAR context. What you have in
    if (undef, undef) { # An extra set of parens doesn't matter. print "OK1\n"; }
    is the comma operator in scalar context. Which evaluates its LHS, throws it away, then returns its RHS. Which is undef, and hence false.
    According to the above
    If with "above" you mean the post you're replying to, you notice I talk about list ASSIGNMENT. Not lists. Nor arrays.

      is the comma operator in scalar context.

      It's funny how you say something doesn't exist right before you say the thing that doesn't exist is what he has. (Sure, you used a different name for it.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-04-20 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (486 votes), past polls