Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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.

Replies are listed 'Best First'.
Re^2: What is the best way to compare variables so that different types are non-equal?
by LanX (Bishop) 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?
[Corion]: marto: Ow! You got hit by the storm that is bringing warm weather to me ...
[1nickt]: marto Good to hear that was the worst of it for you...
[marto]: 1nickt the worst I'm aware of at the moment :P
LanX .♩..♬ ... Another one bites the Sahara dust ...
marto wonders what fresh hell the firefox update has brought, apart from maxing out CPUs

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-10-17 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (230 votes). Check out past polls.

    Notices?