Two approaches suggest themselves: One is to slurp the entire file into memory, and then use /m or /s to build a regexp that spans lines, doing a substitution on the entire block in one swell s///gs.

If you can't fit the file into memory, or fear doing regexps that span lines, you could do a two-pass substitution. On the first pass, build up a hash that maps [get] to the trailing component of the URI, then rewind the file and make the subsitution on the second pass. This lets you use simple regexps.

If you haven't done regexps that match multiple lines, now's your chance. Go with method 1, and add to your bag of tricks.


In reply to Re: Need RegEx assistance by dws
in thread Need RegEx assistance 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.