daemonchild has asked for the wisdom of the Perl Monks concerning the following question:
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>) {
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mac win and unix EOL chars
by nardo (Friar) on Jun 26, 2000 at 09:40 UTC | |
|
Re: mac win and unix EOL chars
by mdillon (Priest) on Jun 26, 2000 at 12:55 UTC | |
|
Re: mac win and unix EOL chars
by athomason (Curate) on Jun 26, 2000 at 12:24 UTC |