Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Newlines: reading files that were created on other platforms

by bobf (Monsignor)
on Feb 02, 2005 at 22:29 UTC ( [id://427453] : note . print w/replies, xml ) Need Help??

in reply to Newlines: reading files that were created on other platforms

First of all, thank you for all of the replies.

To clarify: the input files are just text files created (and edited) by the user. It is possible for a file to be created (or edited) on one platform and then moved to another to be processed, but I expect this to be a rare occurrence. That said, it already happened. :)

After reading the replies here and thinking about this a little more, I think preprocessing is the best way to go in this case. My initial reluctance towards this approach stems only from the fact that each input file will be reprocessed every time the program is run. Thinking out loud: I would be very surprised if any one input file exceeded 1 MB, so slurping it is not an issue with respect to memory. Maybe I could save time by only writing the file back out if a newline character did not match \n (figuring out how to do that will be the next step - perhaps using binmode to make sure they don't get converted to \n on input (per monkey_boy's suggestion), or something like msemtd's example). I will also look into adamk's File::LocalizeNewlines module.

periapt and Drgan summed up the implementation and advantage of this approach quite nicely. I'll write a sub to preprocess the files and see how it goes.

Thanks again for the comments. I appreciate the input.