"Strange" is relative. If you come from another programming language, say PHP, then it may seem strage at first. But when you think about it, it actually makes perfect sense, since it makes the distinction between number- and string comparisons much clearer.
Although, if you really wanted to, you could probably overload == to do string comparisons as well.
| [reply] [d/l] |
Not strange if you came from Unix shell, which also
uses different operators for numeric versus string
comparison. :)
Some background as to why Perl has string and numeric
operators can be found
in Modern Perl in the "Numeric, String, and Boolean Context" section on page eight:
In exchange for not having to declare (or at least track)
explicitly what type of data a variable contains or
a function produces, Perl offers specific type contexts
that tell the compiler how to treat a given value during
an operation ...
The eq operator treats its operands as strings by
enforcing string context on them.
The == operator imposes numeric context ...
Perl will do its best to coerce values to the proper type
depending on the operators you use. Be sure to use the
proper operator for the type of context you want.
This issue was discussed in gory detail a month ago
in: Definition of numerically equal and rationale for 'you' == 'me'.
| [reply] [d/l] [select] |
| [reply] |