in reply to Counting repeated values from an array
my %count; foreach my $element( @name ) { ++$count{$element}; } foreach my $element( keys %count ) { print "$element = $count{$element}\n"; }
If you want to sort the names alphabetically, use foreach my $element( sort keys %count). If you want to sort by highest count first, use foreach my $element( sort { $count{$b} <=> $count{$a} } )
Do yourself a favour and invest in the Perl Cookbook. It's chock full of useful Perl idioms like this. It's money well spent -- and the only Perl title that never moves far from my console.
update: changed the title of this node to reflect that of the parent node.
--
|
|---|