in reply to Re^3: Problems with changing $/ and Tie::File in RO mode (:crlf)
in thread Problems with changing $/ and Tie::File in RO mode
Hi almut,
I'm sorry, this excursion was very interisting, but that *may* work from the unix side, but on my both XP systems (v5.8.8 and v5.10.0 with komodo) it doesn't work; the yield is only *one* array element.
BUT I have to apologize! The solution is written in the 'ActivePerl User Guide -- Tie::File', witch I did read some times before.
There is another parameter called 'recsep' that worked very well for me. So here is the code.
use Tie::File; # Record separator per default = $/ use Fcntl 'O_RDONLY'; # open in read-only mode my ($sep1, $sep2) = ($ENV{'windir'}) # determine OS ? ("\r\n", "\n") : ("\n", "\r\n"); my $file = shift @ARGV; tie my @array, 'Tie::File', $file, mode => O_RDONLY, memory => 0, recsep => $sep1 or die $!; my $n_recs = @array; # how many records are in the file? unless ($n_recs > 1) { untie @array; tie @array, 'Tie::File', $file, mode => O_RDONLY, memory => 0, recsep => $sep2 or die $!; $n_recs = @array; print join ("~SEP~", @array); die "Found only one array element\n" unless $n_recs > 1; }
Voila! Proggy dies not (in XP).
Nevertheless thanx for your help, almut.
... And I'm still wondering, why neither changing of $/ nor the setting of "<:unix" had any effect at all.
|
|---|