Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: What is the best way to compare variables so that different types are non-equal? (overloading "cmp")

by ikegami (Patriarch)
on Jul 20, 2009 at 08:09 UTC ( [id://781563]=note: print w/replies, xml ) Need Help??


in reply to Re: What is the best way to compare variables so that different types are non-equal? (overloading "cmp")
in thread What is the best way to compare variables so that different types are non-equal?

Globally changing the behaviour of regex is very wrong. You don't even gain anything from it. The compare function could just as easily be outside of the class.
  • Comment on Re^2: What is the best way to compare variables so that different types are non-equal? (overloading "cmp")

Replies are listed 'Best First'.
Re^3: What is the best way to compare variables so that different types are non-equal? (overloading "cmp")
by LanX (Saint) on Jul 20, 2009 at 22:35 UTC
    Well as I already said
    I certainly don't recommend it for production use
    , a simple comparison function is much easier to maintain. But Beth asked for options with overloading, and thats the answer.

    If one really needs the behavior of a JS-like === very often this could be a way to achieve it. The old behavior of comparing only the stringified values could still be achieved by explicitly stringifying the arguments, e.g.:  "$rx" cmp "$ry".

    IMHO not overloading is the problem in perl5 but the lack of alternative or freely named operators. Actually overloading results in compatibility problems.

    Anyway the fact that it's "a global change of regex" really surprises me, I expected it to be reduced only to the scope of the file...

    Cheers Rolf

      I expected it to be reduced only to the scope of the file...

      There's only one Rexexp package, not one per file.

        Im still confused, there is no way to reduce the effect of overloading to just the file which imports a modul with an overloaded Regexp package?

        (except maybe implementing a switch to default behavior within the overloading methods)

        Cheers Rolf

        UPDATE: might be possible with eval 'no overload "cmp"; see Run time Overloading

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://781563]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-04-18 16:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found