Hi, all. I think I'm in way over my head and could use your help.

I am trying to rewrite email alerts from one system so they can generate tickets in a different system. I thought I could get clever and create a template with field names that the program would fill in with values from the incoming email.

When the program encounters a string of the form %-Field Name-% it replaces it with the field with that name in the incoming email. So far, so good.

The problem is that some of the fields need to be trimmed or reformatted. I thought I could add some syntax--hugely ugly, I know--that would let me specify s/// substitutions in the template file, so that %-Incoming Port%%/dev/pts/%%Port Number-% would be read as Print the value of the "Port Number" field, but replace the string "/dev/pts/" with "on Port# ". ALSO working just fine, thankyouverymuch.

Or so I thought until I tried to use () and \1 in the template, anyway. %-Message Text%%.* for (.*) from .*%%\1-% (so that "successful login for root from blah blah" gets rewritten as "root") fails emphatically, miserably, repeatedly, as do I.

I've lost count of the number of things I've tried, but I've been googling, reading, and putzing for about 8 hours now and I'd dearly love a hint. I feel like it must be possible because this much seems to work:

$val=$envalert{$var}; if ($val =~ /$modfrom/) { $replval = $1 ;

When $modfrom contains ()'s, then $1 seems to get set properly. But I can't wrap my head around how to do the rest of the substitution. Any pointers will be gratefully received.


In reply to Regex with variables by eshafto

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.