in reply to Re: How the perl converts LF into CRLF
in thread How the perl converts LF into CRLF

Those won't work on a Windows box because binmode wasn't used.

Replies are listed 'Best First'.
Re^3: How the perl converts LF into CRLF
by schnell18 (Novice) on Jul 03, 2009 at 08:44 UTC
    You are right. Below is the dos2unix equivalent works on Windows
    #!/usr/bin/perl -w use strict; use File::Temp qw(tempfile); use File::Copy; dos_to_unix($ARGV[1]); sub dos_to_unix { my($file) = @_; my($dst, $src); my (undef, $tmpfile) = tempfile(); copy($file, $tmpfile) or die "Can't copy $file to $tmpfile due to: $!\n"; open($dst, ">$file") or die "Can't open $file for write due to: $!\n"; open($src, "<$tmpfile") or die "Can't open $tmpfile for read due to: $!\n"; binmode($dst); while(<$src>) { chomp; print $dst "$_\n"; } close($dst); close($src); }