use strict; # Always use IO::File; # I like to localize filehandles. sub CountPatternInFile { my ( $filename, $pattern, $stop_pattern ) = @_; my $fh = IO::File->new( $filename ) or die $!; my $count = 0; while( <$fh> ) { $count += s/($pattern)/$1/g last if m/$stop_pattern/; } close $fh or die $!; return $count; }
In reply to RE: Counting occurances of a pattern in a file
by Adam
in thread Counting occurances of a pattern in a file
by MadraghRua
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |