in reply to Comparing against multiple values
There are a few solutions that came to my mind:
---
---
---
---
There are more, but these were the ones I like the most :) Have fun ;)
Regards,
octo
P.S.: I didn't do ANY performance tests, so my guesses are likely to be wrong, please don't rely on this!
Propably quite performent if you have to check for these values very often and they never change (CGIs, for example..)my $code = "sub check { my \$val = shift; if ("; $code .= join (' or ', map { "\$val eq \"$_\""; } (@ceck_vals)); $code .= ") { return 1; } else { return 0; } }"; eval $code;
---
Propably the better choice if @check_vals often changes..my %check = map { $_ => 1; } (@ceck_vals); if ($check{$val}) { do_foo (); }
---
I expect it to be kind of slow..if (grep { $val eq $_ } (@check_vals)) { do_foo (); }
---
This is slow, but it can match parts of $val, in case this is needed..my $regex = join ('|', @check_vals); if ($val =~ m/$re/) { do_foo (); }
---
There are more, but these were the ones I like the most :) Have fun ;)
Regards,
octo
P.S.: I didn't do ANY performance tests, so my guesses are likely to be wrong, please don't rely on this!
|
---|
In Section
Seekers of Perl Wisdom