Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.