Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: eq vs. ==

by benn (Vicar)
on Jul 20, 2003 at 12:24 UTC ( [id://276035]=note: print w/replies, xml ) Need Help??


in reply to eq vs. ==

Following on from adrianh, also consider...
print "==" if $a == ($b * $c);
and of course, the potential confusion with..
$a = "2.0"; print "eq" if $a eq "2"; # Nope print "==" if $a == 2; # Yup
Basically, not all equality comparisons are string-based. In my 'perl mindset', if $a == "2", where the number is quoted, immediately begs the question as to which type of comparison is wanted...
if $a eq "2" suggests that $a *generally* holds a non-numeric string...maybe part of something like foreach my $a (split(/\s+/,"my 1 markup 2 scheme where numbers 3 do 2 stuff")),whereas if $a == 2 suggests that $a *always* holds a number (and use warnings will then tell me if it doesn't for any reason).

Cheers, Ben

Log In?
Username:
Password:

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

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

    No recent polls found