obscurifer
Technical User
I'm looking for a simple (or simple-minded) way to convert a text file from DOS-ish CR/LF end-of-line pairs to Unix-ish LF end-of-line characters. It should be pretty straightforward, since Perl contains a robust pattern matching facility. So here's my code.
#! /usr/bin/perl
while($line = <> {
$line =~ s/\015\012/\012/g;
print "$line";
}
I know it can be simplified a bit by using $_ instead of teh $line assignment, but that's not relevant to my question. What this code is supposed to do is take each line of input, find the CR/LF pair, which is represented by the \015\012 octal characters, and replace it with the LF character.
I don't want to simply remove CR characters, because it's possible some files may have lone CR characters for some reason.
After I do the substitution, I print the modified line. Of course, this program will work as a filter with IO redirection to get the input and output files.
So, here's the question. Why does this work correctly on Cygwin's Perl build, but when I use ActiveState's Perl build, I actually get my file back with CR/LF pairs? Is ActiveState so smart that it knows that I really wanted a DOS-ish text file, so it automagically inserted CR characters before LFs? Is this cause for me to be concerned or angry?
#! /usr/bin/perl
while($line = <> {
$line =~ s/\015\012/\012/g;
print "$line";
}
I know it can be simplified a bit by using $_ instead of teh $line assignment, but that's not relevant to my question. What this code is supposed to do is take each line of input, find the CR/LF pair, which is represented by the \015\012 octal characters, and replace it with the LF character.
I don't want to simply remove CR characters, because it's possible some files may have lone CR characters for some reason.
After I do the substitution, I print the modified line. Of course, this program will work as a filter with IO redirection to get the input and output files.
So, here's the question. Why does this work correctly on Cygwin's Perl build, but when I use ActiveState's Perl build, I actually get my file back with CR/LF pairs? Is ActiveState so smart that it knows that I really wanted a DOS-ish text file, so it automagically inserted CR characters before LFs? Is this cause for me to be concerned or angry?