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

Another option would be split with capture brackets, like this

#!perl use strict; # create test file open OUT,'>','line.txt' or die; binmode OUT; print OUT "Windows".chr(13).chr(10); print OUT "Unix".chr(10); print OUT "Windows".chr(13).chr(10); open OUT,'>','copy.txt' or die; binmode OUT; open IN,'<','line.txt' or die; binmode IN; while (<IN>){ my ($line,$eol) = split /([\015\012]+)/,$_; # process $line print OUT $line.$eol; }
poj
  • Comment on Re: Copying an ascii text file, replicating end of line terminator (windows or unix)
  • Download Code