When you did
the global match (triggered by /g) was done at scalar context. In this case it finds a single match or fails. So $d will return 1 or 0.my $d = ($n =~ /A/g)
To do what you want, you need to set a list context and then count the matches.
will output "matches 5".my $n = "ABCDABDIDAOFOOFAA" ; my @matches = ($n =~ /A/g); my $d = @matches; print "matches $d";
In reply to Re: how to count matches
by ferreira
in thread how to count matches
by jeanluca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |