Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Comparing against multiple values

by traveler (Parson)
on Mar 18, 2002 at 22:04 UTC ( #152594=note: print w/replies, xml ) Need Help??

in reply to Comparing against multiple values

You could also use Meta::Ds::Hash. Something like this (untested):
use Meta::Ds::Hash; my($hash)=Meta::Ds::Hash->new(); $hash->insert($bar); $hash->insert($baz); $hash->insert($boo); # later if($hash->has($foo)) { print "Found it\n"; }
It would be interesting to compare these various solutions for large and small numbers of comparison sets.

HTH, --traveler

Replies are listed 'Best First'.
Re^2: Comparing against multiple values
by Anonymous Monk on Feb 09, 2018 at 16:03 UTC
    i don't know how to reply to the whole thread so i have used the last answer, sorry for that. if ($foo=~/$bar|$baz|$boo/){ is not strictly equivalent to if (($foo eq $bar) || ($foo eq $baz) || ($foo eq $boo)){ as =~ will be true for $foo=abc and $boo=ab but "abc" will not be eq to "ab" if you want them to be strictly equivalent then it will be something like : if ($foo=~/^$bar$|^$baz$|^$boo$/){ i have tested with string values but not with $var so maybe there is some \ to use at the good places for this to work regards.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://152594]
[choroba]: does your list start with number 5?
[LanX]: -i
LanX it's an imaginary list ...
LanX ... reflecting root problems
choroba uses real lists so he can easily insert as many items in between as needed
LanX questions the integerity of this approach. ..
LanX doesn't sound natural

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (16)
As of 2018-03-20 10:27 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (249 votes). Check out past polls.