Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: eq vs. ==

by benn (Priest)
on Jul 20, 2003 at 12:24 UTC ( #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


Comment on Re: eq vs. ==
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-10-01 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (40 votes), past polls