|
|
| "be consistent" | |
| PerlMonks |
Re: Using grep in a scalar contextby AnomalousMonk (Prior) |
| on Feb 06, 2013 at 13:16 UTC ( #1017420=note: print w/ replies, xml ) | Need Help?? |
|
You say the approach you are using is "not working", leaving us to guess what data you are using and what result you expect. My guesses are that either you want to count the number of strings in a dataset (i.e., an array) in which a pattern occurs at least once, or you want to count the total occurrences of a pattern in all strings in a dataset. The code you posted seems to serve for the first purpose. A variation using map seems to take care of the other. (Note that the pattern occurs twice in 'zAAzAAz'.) In neither case is the original dataset changed.
Update: Do we need to consider the question of overlapping versus non-overlapping pattern matches? I.e., How many matches are there in 'xAAAx'?
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||