Damian Conway wrote:
> I often need a generic comparison test (typically for equality of less-than),
> and to get it one has to jump through hoops:
>
> sub generic_eq {
> my $failed;
> local SIG{__WARN__} = { $failed = 1 };
> return $_[0] eq $_[1] || $_[0]==$_[1] && !$failed;
> }
>
> I want generic equality to DWIM. I.e. are these the same (for some
> reasonable value of "same").
The above sub would make more sense if you tried numeric equality (which might
fail) first, and then string equality. But as written, the warning will never
occur, and ||'s rhs will never execute. In some sense, "eq" is already the
generic equality operator you are looking for.
Perhaps the RFC would be better written that eq should be optimized so that if
both sides are numerics, that the numeric values are compared rather than
converting both to strings, and comparing the results. But that would be best
done on -internals.
On the other hand, that will not handle the cases where a comparison is to be
done on "007" and "7"... the conversion to numeric is required then, to get
numeric comparison rather than lexicographic.
> And "dog"=="cat" is not a reasonable value of "same".
>
> Damian
--
Glenn
=====
There are two kinds of people, those
who finish what they start, and so
on... -- Robert Byrne
_______________________________________________
Why pay for something you could get for free?
NetZero provides FREE Internet Access and Email
http://www.netzero.net/download/index.html