Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: eq vs. ==

by benn (Vicar)
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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://276035]
and the voices are still...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-12-11 17:33 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (309 votes). Check out past polls.