0: sub count_occurrences{
1: my($part, $whole, $cs)=@_;
2:
3: # $part -- the text you're searching for
4: # $whole - the string within you're searching
5: # $cs -- case sensitive? 1=yes, 0=no (may be omitted for non cs search)
6:
7: my($count)=0;
8: my($null)="\0";
9: if($cs==1){
10: while($whole=~/$part/s){
11: $count++;
12: $whole=~s/$part/$null/;
13: }
14: }else{
15: while($whole=~/$part/is){
16: $count++;
17: $whole=~s/$part/$null/i;
18: }
19: }
20: return $count;
21: } In reply to Count String Occurrences by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |