I have written a script that parses data from a delimited text file. The script works fine, except doesn't deal well with EOL characters from different OS's (i'm stuck in win32 for the purposes of this script).
Anybody have a code snippet that will detect what the EOL char of the file is, and set $/ accordingly? I've tried various regexps using things like
if ($_ =~ /\r\n/) { $os = "win"; $/ = "\r\n"; } if ($_ =~ /[^\r]/ && $_ =~ /\n/) { $os = "unix"; $/ = "\n"; } if ($_ =~ /[^\n]/ && $_ =~ /\r/) {$os = "mac"; $/ = "\r"; }
but they don't seem to work for me. Do those look right? Does my problem lie elsewhere in the code? Is there a better way, that doesn't involve checking the EOL every iteration of the loop? (the above code is below the
line ). Any help would be appreciated.while(<FILE>) {
In reply to mac win and unix EOL chars, $/ question by daemonchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |