I have to read a big (BIG) file in memory, line by line, using perl. In case of some error, function open() does return false and $! is set to the system error. But, if I get some errors reading the file? I use this code:
open(STATISTICS, "<" . $statisticsFile) or die "Can't open statistics file $statisticsFile ($!)";
while (<STATISTICS>) {
my $line = $_;
...
}
close($STATISTICS);
Any hint?
You can change your code to work as shown below.
You seem to be using both STATISTICS and $STATISTICS for your file handle. Since lexical handles are prefereable I have used $stat here.
open my $stat, "<" . $statisticsFile
or die "Can't open statistics file $statisticsFile: $!";
until (eof $stat) {
my $line = <$stat>;
defined $line or die "Read failure on statistics file $statisticsFile: $!";
...
}
close($stat);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With