If you only strip carriage returns and then handle or save it as text, the
remaining linefeed may automatically be converted back to carriage return,
linefeed pair.
If I may say so, that's a bit of a muddled presentation. There
shouldn't be any "may" about it: the behaviour in each situation is
clearly defined - one just has to know what it is.
I'd definitely recommend that the O.P read perldoc perlport with some
care, to get a fuller picture.
The issues are:
- which platform are we talking about?
- are we dealing with platform-native data, or could it be
platform-foreign?
- are we handling it in text mode or in binary mode?
(this last point gets more complex when we also have encoding
layers involved...)
If you're handling platform-native text data, and handling it in
text mode, then inside of your Perl program the newlines will be
"\n" (the associated \r being stripped off on input, and added on
output).
You may have to handle it in binmode to avoid that (or
remove them in an OS that does not use carriage returns for newlines).
In Windows "\n" eq "\015\012"
See above! In text mode I/O, "\n" is "\012" internally.
Not if you're reading DOS-format data!
In fact the situation _could_ be just the opposite of what you said:
if the platform is Windows/DOS and you're working in text mode, then
with DOS-format data, the \015 will be removed on input; but if the
platform is Unix and the data is in DOS format, then on Unix you'll
get \015\012 _even_ when reading in text mode.
OK. (...and then there's EBCDIC-based platforms ;-)
all the best