in reply to Fetching 3 letters only
Remember, when you need to count occurances, the hash is your friend.
Produces:use strict; my $word = 'abcdefabcdeab'; my ( %counters, $total ); while ( $word =~ /([a-c])/gi ) { $counters{$1}++; } foreach my $letter ( sort keys %counters ) { print "\n$letter: " . $counters{$letter}; $total += $counters{$letter}; } print "\nTotal: $total";
I hope this helps.a: 3 b: 3 c: 2 Total: 8
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Fetching 3 letters only
by Anonymous Monk on May 23, 2003 at 19:38 UTC |