Thanks, Abigail. You're correct: "good" lines should be 322 characters, after inserting the CR LF. Your warning is right on, and it's why I wanted to test whether the file already had any newlines before altering it. From what I saw in the sample data I was given, it was an all-or-nothing problem: the file was either already "good", with all the newlines in the right locations, or else it was missing newlines completely, and needed the \n inserted after every 320 chars.
Today, things have changed a bit (sigh). I'm told the files I'm working with *sometimes* have LFs but not CRs, although I don't have samples like this. Also, the record separator in the "good" files appears to be "CR CR LF" instead of "CR LF", for whatever reason. (These files are output from a buggy 3rd-party program, which we're not likely to get patched.)
I'll need to take these oddities into account, and it sounds like I can't make any assumptions about the files I've got to work with. I'm going to try to work up something that's very generalized, simply makes sure each line of each file is 320 chars with the proper record separator, and warns me if it sees an oddball I didn't know about. You've all given me ideas for nice approaches to this. Much thanks to everyone!
-Peter
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.