Hello,
The following dos2unix one-liners
perl -i~ -pe "s/\r\n$/\n/" <files>
fails in windows. I think it is because when
perl writes the resulting file, it re-inserts \r\n!
The following code almost works:
$^I = '~';
my $file_name = $ARGV[0];
my @lines = ();
while(<>)
{
chomp;
push @lines, $_;
}
open (OUT, ">", $file_name) or die "Unable to open $file_name for
reading:$!\n";
binmode OUT;
print OUT join "\n", @lines;
The above code "almost works" because it removes the very last
line if the very last line was \r\n. This problem can be solved
by replacing chomp with s/\r\n$/\n/ and joining @lines with ''.
The issue I have seen with many of the solutions for dos2unix
(including the gnu win32 version) is that they blindly replace
all \r with nothing thereny removing any ^M embedded within lines
(and I have vim-related files with ^M embedded inside lines).
Anyway, how to fix the one-liner and how to make the multi-liner
terser?
--Suresh
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs