in reply to Re: Help on array element counting
in thread Help on array element counting

Also to illustrate point of 'sort' with hashes, I'd add to this a little. Sorting either by count
@fruits = qw/ MANGO APPLE GRAPES MANGO MANGO MANGO MANGO APPLES APPLES BANANA CORN APPLES /; map { $count{$_}++ } @fruits; foreach (sort {$count{$a} <=> $count{$b}} keys %count) { print "$_ => $count{$_}\n"; }
Or to sort them by fruits (changing the sort)
foreach (sort {lc($a) cmp lc($b)} keys %count) { print "$_ => $count{$_}\n"; }