Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by kyle (Abbot)
on Jul 19, 2009 at 16:31 UTC ( #781467=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?
in thread What is the best way to compare variables so that different types are non-equal?

Regex pattern objects are magical. Overloading doesn't even come into play.

Magical is right. This took me by surprise.

use overload; use Scalar::Util qw( blessed ); use Test::More 'tests' => 4; my $rx = qr/a/; ok blessed $rx, 'Regexp is blessed'; ok ! overload::Overloaded( $rx ), 'Regexp is overloaded'; ok ! overload::Method( $rx, q{""} ), 'Regexp has q{""} overloaded'; isnt "$rx", overload::StrVal( $rx ), 'StrVal of regexp isnt regexp stringified';


Comment on Re^2: What is the best way to compare variables so that different types are non-equal?
Download Code
Replies are listed 'Best First'.
Re^3: What is the best way to compare variables so that different types are non-equal?
by LanX (Canon) on Jul 19, 2009 at 22:17 UTC
    ok ! overload::Overloaded( $rx ), 'Regexp is overloaded'; ok ! overload::Method( $rx, q{""} ), 'Regexp has q{""} overloaded';
    I'm confused shouldn't it say "is not" and "has not"?

    Cheers Rolf

      You're right. I originally wrote the descriptions to match the tests, and then I was surprised when I ran them (they failed). After that, I reversed the tests and forgot to rephrase the descriptions.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2015-07-30 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls