Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Can't understand function returning undefs

by rg0now (Chaplain)
on Sep 24, 2010 at 21:50 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://861899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-19 01:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found