in reply to Re: chomp() is confusing
in thread Why chomp() is not considering carriage-return
If you run your script on Windows, the carrage return and newline will both be removed (since it's expected that under Windows files will end in both a carriage return and a newline).
That's completely wrong. Perl automatically converts CRLF to LF when reading text, so $/ is set to LF ("\n"). Your script shouldn't see CR at all, so chomp only removes the LF.
Now, if you were dealing with binary data, chomp won't work (without changing $/) because chomp is a text function.
print(unpack('H*', $/), "\n"); # 0a Just LF
my $str = <DATA>;
print(unpack('H*', $str), "\n"); # 746573740a No CR
print(unpack('H*', $str), "\n"); # 74657374 LF chomped.
If, on the other hand, you want to run a script that will strip the EOL marker off a file regardless of what OS the script is running on and whether that file came from Unix or Windows, you need to do that yourself, with something like:
That regexp is incomplete. It doesn't handle systems that use \r as the EOL marker.