Hi folks,
If I want to count the number of times that a match occurs in a line is
there a way of doing this, if there is I have not found it!
e.g.
$line="This is a sentence about matching sentences.\n";
$line=~/sentence/ig;
So I will have matched "sentence" twice and I want to record this.
I can do it like this:
$line=~/sentence/ig;
# count the number of instances of this in the sentence
@split=split(/sentence/,$line);
[EMAIL PROTECTED];
$length--;
This code works fine, but if I need to keep each matched term (as I
have wild-cards to capture spelling variants).
i.e. output would be:
sentence
sentece
Is there a way to automatically capture each individual match (e.g.
using a special array character?)
Sorry for the long-winded question, any help appreciated!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>