$Bill wrote:
>Suresh Govindachar wrote:
>>
>> 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:
>>
>> [snipped]
>>
>> 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).
>>
>> [...]
>
> Try:
>
> $^I = '~'; no warnings 'once';
> while (<>) { binmode ARGVOUT if $. == 1; print; }
The following worked -- didn't need to turn off warnings.
#!/usr/bin/perl
BEGIN {(*STDERR = *STDOUT) || die;}
use diagnostics;
use warnings;
use strict;
$| = 1;
$^I = '~';
while (<>)
{
binmode ARGVOUT if $. == 1;
s/\r\n$/\n/;
print;
}
And the one-liner becomes:
perl -i~ -pe "binmode ARGVOUT if $.==1; s/\r\n$/\n/;" <dossy files>
Thanks,
--Suresh
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs