As sysread() doesn't use buffers, it's probably more efficient to use normal
reads. Also, splitting lines by yourself (i.e. in Perl) won't be as efficient
as in C implementation. Thus I recommend to use
open(FILEH, "database/$_") or die "$!";
my @tempfile = <FILEH>;
close FILEH;
my $lines = scalar @tempfile;
print " - $lines entries\n";
Yo don't need to handle zero lines in special way, I think.
On Monday 16 July 2001 14:55, Martijn van Exel wrote:
> Subscribers,
>
> I'm trying to get a line count for a number of files. Is sysread() the
> preferred (fastest, most efficient) way to go (snippet 1) or should I
> read the file into an array and count the array instead (something like
> snippet 2, untested)?
>
> Thanks for your insights.
>
> $_ contains the filename in both snippets.
>
> # code snippet 1
> open(FILEH, "database/$_") or die "$!";
> while (sysread FILEH, $buffer, 4096) {
> $lines += ($buffer =~ tr/\n//);
> }
> close FILEH;
> $lines = 0 if !$lines;
> print " - $lines entries\n";
>
> #code snippet 2
> open(FILEH, "database/$_") or die "$!";
> @temp = FILEH;
> close FILEH;
> $lines = @tempfile;
> $lines = 0 if !$lines;
> print " - $lines entries\n";
--
Ondrej Par
Internet Securities
Software Engineer
e-mail: [EMAIL PROTECTED]
Phone: +420 2 222 543 45 ext. 112
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]