in reply to Insert at regular increments

Does that mean that "good" lines are 322 characters long? That is, 320 characters + CR LF? Because if it is, any solution that blindly splits on 320 characters, be it by using //, substr or by setting $/ = \320 will fail on files that have good lines in them.

Abigail

Replies are listed 'Best First'.
Re: Re: Insert at regular increments
by EyeOpener (Scribe) on Jul 23, 2002 at 17:23 UTC
    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