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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2018-06-25 10:58 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.