If the things in @params are just words (i.e., no regular expression special characters), you probably want to make a single regular expression out of them ahead of time and rewrite the inner loop like so:
[ . . . snip . . . ]
Of course, even if they contain regular expression special characters you might want to do this, but be really careful about it. :-)

You should be careful even if they don't contain metacharacters.

In this case, the whitespace helps to anchor the expression, but you shouldn't rely on that. For instance, what if you have both "foo" and "foo\t" in your array? (Which gets matched may depend on the order they appear in the expression.) Be especially wary of changing the rest of the regular expression or trying to re-use $paramre in another one.

Also, you would need to add a /g modifier and loop over the matches to get the same behavior as the original.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Re: Using expressions in arrays for pattern matching by sauoq
in thread Using expressions in arrays for pattern matching by Mike_76

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.