in reply to Re: Looking for a better way to get the number of lines in a file...
in thread Looking for a better way to get the number of lines in a file...

This is an adaptation of... um... I think recipe 8.6 in Cookbook, "Picking a random line from a file", though I may have seen it elsewhere. (Corrections? Credit?)
#!/usr/bin/perl open ( FH,'data' ) or die ( "data: $!\n" ); while( <FH> ) { if ( eof ( FH ) ) { print $. } }
What I like about this is that you aren't storing anything in memory - so this should wade through a 2GB file (as mentioned fearfully later in this thread) fairly quickly.

blyman setenv EXINIT 'set noai ts=2'

  • Comment on Re: Re: Looking for a better way to get the number of lines in a file...
  • Download Code