Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How come undef eq '' ??

by tmharish (Friar)
on Jan 30, 2013 at 15:45 UTC ( #1016087=note: print w/ replies, xml ) Need Help??


in reply to How come undef eq '' ??

Not to get into a discussion on what perl should do but:

perl -e 'if( $tmp eq 0 ) { print "In\n" } else { print "Out\n" }' Out

By the same logic - I cant seem to understand why this is not true! Especially considering undef $a; $a++ works as expected.


Comment on Re: How come undef eq '' ??
Select or Download Code
Replies are listed 'Best First'.
Re^2: How come undef eq '' ??
by muba (Priest) on Jan 30, 2013 at 15:55 UTC

    Because eq is for string comparisons. undef stringifies to "", 0 stringifies to "0", and "" ne "0".

    Change eq to == and it will print "In".

Re^2: How come undef eq '' ??
by Corion (Pope) on Jan 30, 2013 at 15:53 UTC

    eq is for string comparison. ++ is a numeric operator. Maybe that's where the root of the preceived discrepancy lies?

Re^2: How come undef eq '' ??
by tmharish (Friar) on Jan 30, 2013 at 16:53 UTC

    Corion, muba ... Yup, with the 0 I should have used == and it would have been consistent with eq and ''.

    Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2015-07-31 18:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (280 votes), past polls