|more useful options
Re: Double interpolation of captured substringsby bobf (Monsignor)
|on Nov 17, 2004 at 23:26 UTC
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!