I ran into a similar problem a while ago. You may find the solutions presented in Newlines: reading files that were created on other platforms to be helpful. The two main options that I considered were:
I used the latter option. It worked beautifully.
- Use a regex to match the newline character(s) in the file. I think this would require slurping the whole file and then doing something like if( $file =~ m/\015$/ ) (which assumes the file will end with a newline) or if( $file =~ m/\015(?!\012)/ ) (which doesn't), setting $/ according to what matched, and re-reading the file line-by-line. If the file contains different types of newlines this will not work.
- Preprocess the input file to convert all newline characters to the current system's newline character.
$file =~ s[(\015)?\012(?!\015)][\n]g; $file =~ s[(\012)?\015(?!\012)][\n]g;
In reply to Re: line ending troubles
by bobf
in thread line ending troubles
by Dirk80
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |