Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re^3: \r\n at end of line (preserve \r?)by tye (Sage) |
on Apr 19, 2011 at 17:25 UTC ( [id://900177]=note: print w/replies, xml ) | Need Help?? |
It is my experience that most text-processing tools don't preserve newline style (file-copying tools would be a different story). I don't expect it from other tools and I generally don't write tools that do such. If I'm reading newline-terminated lines, then I'm likely processing text, not copying data. I expect tools to write new text files using the default newline style of the tool's platform. That is certainly what will happen with any tool written in C under Windows (unless the developer goes out of their way to change default behavior). A simple "perl -pe1" using native Windows perl will include "\r"s in the output even if the input lines are terminated with just "\n"s (note that I didn't even have to give perl the "-l" option). If you want to preserve newline style, then you want to at least binmode your input and output. Then you can decide whether you want to try to preserve inconsistent or non-standard newline style. I'm not a fan of either so I'd probably just support two output choices, either always "\n" or always "\r\n".
But at this point I don't see ever wanting to do that. :) - tye
In Section
Seekers of Perl Wisdom
|
|