Usual way:
my @strings = qw/ a a b c a b c d e a b c a b c d /; my %count; foreach ( @strings ) { $count{$_} ||= 0; $count{$_}++; } # Then, if you want to sort the results by value: foreach ( sort { $count{$a} <=> $count{$b} } keys %count ) { print "$_ => $count{$_}\n"; }
In reply to Re^3: using hashes to count
by nferraz
in thread using hashes to count
by spiros
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |