in reply to Help - Counting text - Associative Array?
Also, you want to count several things, but you have your count as a single scalar value. That's not going to work.
If the values appear alone, you could do something like
Note that I've made count into a hash with the same keys as %exe, and that I've exchanged == (numeric equality) with eq (string equality).while (<FILE>) { chomp; foreach $key (keys %exe) { $count{$_}++ if ($_ eq $key); } } foreach $key (keys %exe) { print "Name:$key\t Count:$count{$key}\n"; }
If the strings you're looking for aren't the only thing in each line you read, you'd better use index or a regex to find them - string comparison won't work.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Help - Counting text - Associative Array?
by Mr_Lowry (Initiate) on Mar 19, 2004 at 20:32 UTC |