Suppose I use an s/// to alter a string but also to capture some substrings en passant. Suppose I have lots of pairs of capturing parentheses, so in order to put each substring into its own scalar I have to do something like my ($alpha, $beta, $gamma, $delta, $epsilon, $zeta) = ($1, $2, $3, $4, $5, $6);. But that seems redundant, as well as a little dangerous, since every time I add or remove a pair of capturing parentheses I have to remember not only to add or remove an lvalue but also to resize the list of rvalues.

What I'd really like to be able to do is something like my ($alpha, $beta, $gamma, $delta, $epsilon, $zeta) = @SOMEVAR;, where @SOMEVAR is one of those obscure punctuation variables. Except no such variable seems to exist. I can imagine various hacks to simulate one, like using symbolic references to collect $1 through ${@+}, and I can imagine workarounds, like using named captures. But I think there really ought to be a simple, fast, unlikely-to-break way to get all the (anonymous) captures from the last successful match as a list. Anybody know of one?

(Note that since I'm using s/// instead of m//, the return value of the pattern-matching operation isn't helpful.)


In reply to Get all captured substrings after a substitution by Polynomial

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.