"Just so you realize that you've hardcoded a solution for a single data set, whereas some of the other posted solutions are more generalized."

Actually, yes. The "hardcoded" solution provided works in a much larger set of scenarios than the home-grown regex solutions provided. What if there are 200 ^M characters before and after the wrapped key? jeffa's solution handles that (these regexes do not). What if every single key wraps, regardless of width? Again, his solution handles that.

The other solutions, while unary and interesting on their own, are actually much more "hardcoded" (i.e. will only work on a very small subset of the strings involved) than the solution jeffa provided.

Can each of the other solutions be modified to work with all scenarios? Yes, sure, but at what cost and maintenance headache a year from now?

Can jeffa's solution be modified to not be so hard-coded? Yes, and with a much longer-term benefit and maintenance advantage over debugging regexes each time the template format changes ever-so-slightly.


In reply to Re: Unwrapping values in a template by hacker
in thread Unwrapping values in a template by hacker

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.