There are a few solutions that came to my mind:
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 quite performent if you have to check for these values very often and they never change (CGIs, for example..)
---
my %check = map { $_ => 1; } (@ceck_vals); if ($check{$val}) { do_foo (); }
Propably the better choice if @check_vals often changes..
---
if (grep { $val eq $_ } (@check_vals)) { do_foo (); }
I expect it to be kind of slow..
---
my $regex = join ('|', @check_vals); if ($val =~ m/$re/) { do_foo (); }
This is slow, but it can match parts of $val, in case this is needed..
---
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 reply to Re: Comparing against multiple values by flocto
in thread Comparing against multiple values by doran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.