in reply to Copying an ascii text file, replicating end of line terminator (windows or unix)

Hi luckycat,

you could read the first line of the file outside of the main loop (before entering the loop). Something like this:

my $first_line = (<$IN>); my $endofline = $first_line =~ /\r\n$/ ? "\r\n" : "\n"; # process first line ... while (my $line = <$IN>) { # ... }
It makes the program a bit more complicated, because you need to process the first line separately, but it might be worth it if your file is really large. If the file has a moderate size, I would probably not care about trying to be more efficient by checking only once the end-of-line characters.
  • Comment on Re: Copying an ascii text file, replicating end of line terminator (windows or unix)
  • Download Code