Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Thank you all for your responses. gaal and Arunbear's suggestion to save the matches in an array and then stringify them later looks like the best option (at least for now). Some of the patterns contain other (non-captured) text, so I'll have to use something a bit trickier than just taking a slice, but the overall idea should work fine.

ihb's recommendation of String::Interpolate is definitely one I'll file away for later, and the quote/eval example clearly showed what I was missing in my initial attempts. I like the code provided by BrowserUk and Fletch, as it is more generalizable than what I have now, but one of my goals is to keep the formats of the returned strings encapsulated in the function itself. That way if one of the formats is changed I only have to update the values in the hash, rather than track down every call that uses that specific format and update each one individually. TedPride's solution is a clever use of split, but unfortunately the variety of input data is such that coming up with a generalizable split would be difficult.

In summary, I think I'll start by throwing the captured values into an array and then using indices to access them, rather than trying to interpolate $1, etc directly. Thanks again for all of the creative (and better yet, functional!) examples. I've definitely got a good start now, but if any alternative ideas come to mind, I'd love to hear them!


In reply to Re: Double interpolation of captured substrings by bobf
in thread Double interpolation of captured substrings by bobf

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (6)
    As of 2014-08-02 02:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Who would be the most fun to work for?















      Results (53 votes), past polls