Very close, except for a few little mistakes: "(\Q$_)" must be "(\Q$_\E)", or else the closing paren will be escaped. But you don't want parens there anyway, it has to be one single capture group: my $rx =  qr/(@{[ join '|', map quotemeta, keys %m_info ]})/; Another, significantly more involved method that I first came up with when I encountered such a problem:
my $rx = qr/@{ [ join '|', map "(\Q$_->[0]\E)", @m_info ] }/; for my $record (@data) { if (my @match = $record->[1] =~ $regex) { my ($m) = grep defined $match[$_], 0 .. $#match; $record->[1] = join "_", $m_info[$m]->[3], $m_info[$m]->[1]; } }
The hash method is definitely preferrable though. Reasons to choose one over the other: a large @m_info will take less memory, a large %m_info will provide much faster lookups than the grep loop. So long as memory is not a constraint, the hash is the better choice as the code is both faster and more readable.

Makeshifts last the longest.


In reply to Re^2: More efficient Data Structure needed by Aristotle
in thread More efficient Data Structure needed by Anonymous Monk

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.