I would prefer your second solution, to strip the \n's first. Just like you, I would like to have a fancy regexp to do it, but if you install regexp's everywhere regardless whether it is the best solution for that particular case, it will turn out to be awkward, instead of smart. If you cannot come up a lean and clean regexp, I would rather not use it, remember regexp can be really difficult to understand. Especially in a corporate environment, you may well confuse whoever unfortunately has to maintain your code.
In your case, the problem is not just the \n's can come up at any random places within the replaced strings, there is another problem which is equally annoying, if not even worse: where to put the \n's in your replacing strings, so that it satisfies the 80-char restriction? Even worse, you may well have to shift all those \n's in all continue lines, within that logic record (,as it is possible that your logic record can spread into more than two lines). All what I am saying is that, there is a large chance, that you have to reformat your lines, lots of them, if not all.
Have said all this, I really see a clean solution would be:
- strip those \n's caused by 80-char restriction. (You may have two types of \n's, one is the logical record separator, one is caused by the 80-char restriction. This is not clearly described in your post, I just go with a more complete thinking.)
- do a s///, you don't need any fancy one, just a plain normal one, which anyone can come up in one second.
- Reformat to satisfy the 80-char restriction.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.