luckycat has asked for the wisdom of the Perl Monks concerning the following question:
Then here's the code for the processed line I'd write out:my $endofline = ( /\r\n$/ ) ? "\r\n" : "\n";
My script works but I'm wondering if there's a better, cleaner way to do this? Currently I'm doing the end of line check within the while loop that processes each line of the input file so every single line is checked which is probably not efficient. I wanted to guard against the case where you could possibly have mixed windows and unix end of line terminators in the same file. However if that's extremely rare I guess I could remove the check from within the while loop that processes each line of the input file. If I do that, how would I get the type of line terminator the file uses so I know what to use in the print statement later? Basically is there a better way to do what I'm trying to do. Thanks for any tips.print OUTFILE "$processed_string","$endofline";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Copying an ascii text file, replicating end of line terminator (windows or unix)
by Eily (Monsignor) on Jul 24, 2015 at 08:52 UTC | |
|
Re: Copying an ascii text file, replicating end of line terminator (windows or unix)
by Laurent_R (Canon) on Jul 24, 2015 at 08:43 UTC | |
|
Re: Copying an ascii text file, replicating end of line terminator (windows or unix)
by poj (Abbot) on Jul 24, 2015 at 12:30 UTC | |
|
Re: Copying an ascii text file, replicating end of line terminator (windows or unix)
by flexvault (Monsignor) on Jul 24, 2015 at 12:09 UTC |