Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by psini (Deacon)
on Jul 19, 2009 at 16:01 UTC ( #781454=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?

I really don't understand your example. I substituted warns with prints:

use strict; use warnings; my $re =qr{a}; my $re2 =qr{a}; print $re == $re2,"\n"; print $re2 == $re2,"\n"; print 0+$re,"\n"; print 0+$re2,"\n";

and this is the result:

sini@ordinalfabetix:~$ ./x.pl 1 135589228 135591376 sini@ordinalfabetix:~$

The last two lines are NOT equal, because are references to two different scalars. And, as a consequence, $re != $re2 (and $re == $re, but it was expected).

So numerical comparison doesn't tell you if two regex are equal, but only if they are the same (reference).

Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

  • Comment on Re^2: What is the best way to compare variables so that different types are non-equal?
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://781454]
help
Chatterbox?
[Wcool]: hi there
[Wcool]: Does anyone know how to assign STDOUT to a file var in perl6?
[choroba]: hey
[Wcool]: i.e. eequivalent of
[Wcool]: $fh_out = *STDOUT;
[davido]: (a late response) That is so true corion

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (17)
As of 2017-03-23 15:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (289 votes). Check out past polls.