in reply to alter $/ - but why?
Because of the first, the whole structure is kind of odd anyway, since with Mac line endings, you'd slurp the whole file to find out that you have those line endings.
Better to do:
open IN, '<', $filename or die ("Can't open $filename: $!"); sysseek IN, -5, 2; my $last_five; sysread IN, $last_five, 5; ## find out what the EOL chars are and set $\ to match $/ = $1 if $last_five =~ m/(\r{0,1}\n)$/s; sysseek IN,0,0; while (<IN>) { chomp; # now process stuff # }
This is predicated on the text-files being well-formed (ending with an EOL before EOF), so you may need to handle the possibility of malformed files or whatnot.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: alter $/ - but why?
by Anonymous Monk on Aug 04, 2005 at 10:09 UTC | |
by radiantmatrix (Parson) on Aug 04, 2005 at 18:21 UTC |