File::CountLines

Efficiently count the number of line breaks in a file.
Download

File::CountLines Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Moritz Lenz
  • Publisher web site:
  • http://moritz.faui2k3.org/en/mowyw

File::CountLines Tags


File::CountLines Description

Efficiently count the number of line breaks in a file. File::CountLines is a Perl module that can efficiently count the number of line breaks in a file.SYNOPSIS use File::CountLines qw(count_lines); my $no_of_lines = count_lines('/etc/passwd'); # other uses my $carriage_returns = count_lines( 'path/to/file.txt', style => 'cr', ); # possible styles are 'native' (the default), 'cr', 'lf'perlfaq5 answers the question on how to count the number of lines in a file. This module is a convenient wrapper around that method, with additional options.More specifically, it counts the number of line breaks rather than lines. On Unix systems nearlly all text files end with a newline (by convention), so usually the number of lines and number of line breaks is equal.Since different operating systems have different ideas of what a newline is, you can specifiy a style option, which can be one of the following values:nativeThis takes Perl's as the line separator, which should be the right thing in most cases. See perlport for details. This is the default.crTake a carriage return as line separator (MacOS style)lfTake a line feed as line separator (Unix style)crlfTake a carriage return followed by a line feed as separator (Microsoft Windows style)Alternatively you can specify an arbitrary separator like this: my $lists = count_lines($file, separator => 'end{itemize}');It is taken verbatim and searched for in the file.The file is read in equally sized blocks. The size of the blocks can be supplied with the blocksize option. The default is 4096, and can be changed by setting $File::CountLines::BlockSize.Do not use a block size smaller than the length of the separator, that might produce wrong results. (In general there's no reason to chose a smaller block size at all. Depending on your size a larger block size might speed up things a bit.) Requirements: · Perl


File::CountLines Related Software