in reply to RE: Counting occurances of a pattern in a file
in thread Counting occurances of a pattern in a file
use strict; # Always use IO::File; # I like to localize filehandles. sub CountPatternInFile { local $/; my ( $filename, $pattern, $stop_pattern ) = @_; my $fh = IO::File->new( $filename ) or die $!; $_ = <$fh>; close $fh or warn $!; ($_) = split /$stop_pattern/; return s/($pattern)/$1/g; }
|
|---|