Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by tilly (Archbishop)
on Jul 20, 2009 at 13:33 UTC ( #781620=note: print w/ replies, xml ) Need Help??


in reply to What is the best way to compare variables so that different types are non-equal?

In addition to all other suggestions, if you're walking through a fixed data structure and want to prevent going to the same node twice, it can be worthwhile to numify references to nodes. That is instead of trying to look at, say, $foo{$bar} and see if you've been there, look at 0 + \$foo{$bar} instead.

This tests whether the underlying scalar has been seen, and will not care if the value is, or looks like, one that you've seen before.


Comment on Re: What is the best way to compare variables so that different types are non-equal?
Select or Download Code
Re^2: What is the best way to compare variables so that different types are non-equal?
by LanX (Canon) on Jul 21, 2009 at 09:58 UTC
    Explicitly numifying references never came to my mind, only stringifying... That's a very valuable trick in some occasions...

    Just voting once is not enough! 8)

    Thank you!

    Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2014-09-19 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls