On 2012-08-20 22:39, Rajeev Prasad wrote:
> just want to find out in how many records string was found:
>
> my $count=0;
> seek $tmp_FH,0,0;
> while (<$tmp_FH>)
> {
> my $line=$_;chomp($line);
> if ($line=~m/\"$str\"/) {$count++;} #in the file $str string would be in quotes....
> }
>
What if the string is in a line twice?
What if the string contains regex meta characters?
(like a dot or an asterisk)
Alternative:
seek $fh, 0, SEEK_SET;
my $count;
$count +=()= /\Q"$str"/g while <$fh>;
--
Ruud
Thread Previous
|
Thread Next