[Israel.pm] content of big file on windows

Shlomo Yona shlomo at cs.haifa.ac.il
Tue Mar 16 11:07:53 PST 2004


On Tue, 16 Mar 2004, Offer Kaye wrote:

> use strict;
> use warnings;
> 
> my $count;
> my $bigfile = "/path/to/big/file";
> my $lines_from_end = 4;
> 
> open(IN,"$bigfile") or die "Couldn't open $bigfile for reading: $!\n";
> $count += tr/\n/\n/ while sysread(IN, $_, 1048576);
> close(IN) or die "Couldn't close big file after reading: $!\n";
> 
> open(IN,"$bigfile") or die "Couldn't open $bigfile for reading: $!\n";
> while(<IN>){print if ($. > ($count - $lines_from_end))}
> close(IN) or die "Couldn't close big file after reading: $!\n";

What is the meaning of the "magical number" 1048576?
If this is ment to be a very very large size of file in
bytes, wouldn't it be better to use the -s file test unary
operator to return the actual size of the file?

-- 
Shlomo Yona
shlomo at cs.haifa.ac.il
http://cs.haifa.ac.il/~shlomo/




More information about the Perl mailing list