So I hear two votes for using a proper parser and several piecewise suggestions that, unfortunately, don't lend themselves to transforming the entire file in one substitute.

I was hoping there might be some trick like
 $programSource =~ s/in \(('([^']*)'[,])*\)/=~ m#[$2$3$4$5$6$7$8$9]#;/g;
where perhaps the outer group of parentheses would be $1 and any number of nested inner parentheses groups would be matched for all patterns matching ([^']*) inside the single-quotes. In a more broken-out fashion:

$programSource =~ s/in \( (' <-- outer group start goes in $1 ([^']*) <-- inner group chars between '' '[,])* <-- followed by optional comma, close outer group + and repeat outer group for any number of repetitions \)/=~ m#[$2$3$4$5$6$7$8$9]#;/g; <-- put inner grou +ps in match (up to 8 of them, anyway)

Since I'm trying to use global substitutes that can span several lines and update the entire source file in one substitutution, and since there are only three cases in the source I am currently trying to transform, I'll probably just use three separate global substitutes, one for each of the in ('X'), in ('X','Y') and in ('X','Y','Z') cases. It just seems like it ought to be something one could do with a single fancy global substitute.

Thanks for your thoughts.


In reply to Re: Yet another regex question by gregor-e
in thread Yet another regex question by gregor-e

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.