in reply to Re: Re: Counting text strings
in thread Counting text strings

What he did is perform another loop, with each iteration happening everytime the regex matched in the string...
Ala
@test = ('foobarfoo', 'blahbarblah', 'bazbarbarbarbaz'); while (@test) { # # $_ has foobarfoo or blahbarblah or bazbarbarbarbaz # while(/bar/g) { # # matched bar once in foobarfoo inc by 1 # matched bar once in blahbarblah inc by 1 # matched bar 3 times in bazbarbarbarbaz inc by 1 3 times # $count++; print "$count so far\n"; } }
Edit: Sorry for replicating information, Enlil and myself were probably typing at the same time..


/* And the Creator, against his better judgement, wrote man.c */