On May 5, Jos I Boumans said:

>open(I,"$ARGV[0]");
>my @foo = <I>;
>print scalar @foo;

It is considered a dubious practice to read a file into an array; this can
use of lots of memory.  It is particularly wasteful if the goal is just to
find out how many lines there are.

Another wasteful use is:

  @lines = <FILE>;
  for (@lines) { ... }

when a simple:

  while (<FILE>) { ... }

will do.

I have an article about files and filehandling on my web site:

  http://www.pobox.com/~japhy/articles/pa/2000-01.html

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
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

Reply via email to