Deal with the \r\n character during file copy : File Copy « File « Perl






Deal with the \r\n character during file copy

    

$infile = $ARGV[0];
$outfile = $ARGV[1];

open (INFILEHANDLE, "<$infile") or die ("Cannot open file.");
open (OUTFILEHANDLE, ">$outfile") or die ("Cannot open file.");

binmode OUTFILEHANDLE; 

while (defined($line = <INFILEHANDLE>)) {
    $line =~ s/\n/\r\n/g;
    print OUTFILEHANDLE $line;
}

close INFILEHANDLE;
close OUTFILEHANDLE;

   
    
    
    
  








Related examples in the same category

1.File copying
2.Deal with \r character during file copy