Hello, Either nobody in the world has asked this before (unlikely), or my Google-fu is broken (more likely). But I come before the sage Perl monks to ask what seems to me to be an obvious question: According to PerlFAQ, it is apparently "almost" trivial to smart match against a vast swathe of regex patterns by smart matching an array. That's cool. But what if I want to sub out as a result ? For example, assume I've got the ghastly spaghetti-code below :
$cleanLine= $elem; $cleanLine =~ s/\/.*//g; $cleanLine =~ s/\?.*//; $cleanLine =~ s/;.*//; $cleanLine =~ s/;$//; $cleanLine =~ s/\.*//; etc. etc. ad infinitum
How can I make that all awesome, beautiful and able to process faster than the speed of light ? ;-) I assume smart matching arrays will have something to do with it, but if you know better, I'm all ears ! P.S. My example above shows all substitutions being to remove characters, but for extra bonus points, how would I implement different substitutions based on different patterns ?

In reply to Smart match & substitution by OceanPerl

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.