On Jul 16, Martijn van Exel said:
>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)?
Do NOT read a file into an array, unless it's really REALLY *REALLY*
necessary. There are almost ALWAYS better ways to do things.
That said, I wouldn't do:
@lines = <FILE>;
$count = @lines;
I would use either the FAQ's solution with sysread(), or a simple while
loop:
1 while <FILE>;
$count = $.;
For more on $., read perlvar.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]