perlquestion
c
In cleaning up some old code recently, I found a string that can be summed up as:<p>
<code>
if ($val eq '2') {
print 'foo';
}
</code><p>
This looked glaringly wrong to me, however it works. In my current perl mindset, I immediately want to change this to:<p>
<code>
if ($val == '2') {
print 'foo';
}
</code><p>
In my script I am sure that the value of <code>$val</code> will alway be numeric if it is defined at all. However, I'm a bit confused about why <code>==</code> exists if <code>eq</code> works correctly. Reading through <code>perldoc perl</code>, I find the following quote:<p>
<code>
(Why do we have separate numeric and string comparisons? Because
we don't have special variable types, and Perl needs to know
whether to sort numerically (where 99 is less than 100) or
alphabetically (where 100 comes before 99)</code><p>
So does <code>==</code> exist to present a full list of numeric comparison options, when it, unto itself is not necessary?<p>
-[c]