Properly detect line-endings of a file in Perl?
问题 Problem: I have data (mostly in CSV format) produced on both Windows and *nix, and processed mostly on *nix. Windows uses CRLF for line endings and Unix uses LF. For any particular file I don't know whether it has windows or *nix line endings. Up until now, I've been writing something like this to handle the difference: while (<$fh>){ tr/\r\n//d; my @fields = split /,/, $_; # ... } On *nix the \n part is equivalent to chomping, and additionally gets rid of \r (CR) if it's a windows-produced