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";

-- 
Martijn van Exel
WEBkitchen - http://www.webkitchen.nl

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to