in reply to Simple Matching
How about something like this
sub count { # pass it the long sentence and the match word/char! my ($LONG,$CHAR) = @_; my $count = 0; while ($LONG=~m/$CHAR/) { $LONG=~s/$CHAR//; # remove match? $count++; } return $count; }
Then you can call it in your code like this
foreach ( @check ) { print "[$_]: " . count($string,$_); }
Well, it looks a bit messy, but it does exactly what you need with high performance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple Matching
by rnroot (Initiate) on Sep 28, 2009 at 07:29 UTC |