http://www.perlmonks.org?node_id=427453


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.

bobf

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