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.