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


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

Preprocessing input files is not something to be afraid of. Of course, it depends on the flow of your data but it is sometimes more efficient to split the job into two distinct, simpler parts than to try and code one more complex solution.

It seems as if you have a (approximately) a set of client system running something like a data entry or data processing system. You are taking the results from these client systems and loading/processing them into some master program. Even if you are just swapping files among systems, a preprocessing step could be very helpful (your milage may vary). The benefit is that, at a certain point in the flow of data, the data will all look exactly the same regardless of originating/destination platform. That can greatly simplify further processing downstream of that point.

Its worth looking at more closely.

PJ
use strict; use warnings; use diagnostics;
  • Comment on Re: Newlines: reading files that were created on other platforms

Replies are listed 'Best First'.
Re^2: Newlines: reading files that were created on other platforms
by Drgan (Beadle) on Feb 02, 2005 at 17:17 UTC

    I'll have to agree with PJ and adamk here. Checking for each type of newline ending would be horrible, but in a pre-processing situation it might actually speed up the processing time. Another suggestion, not that I'm aware of how the input file is obtained, in the creation of the input file, use a specific newline of your choice to make it uniform and use an output method that would determine what to use when the program is running.

    I.E. Program 1 or Section 1 of program takes user input, uses \015 as a standard newline, instead of a system specific newline and creates the input file with that format. Upon use of the input file, the program then spits out system specific newline for "display" of the file.

    "I have said, Ye are gods; and all of you are children of the most High." - Psalms 82:6