1 2 3 4 5 6 7 8 9 10 11 12 13 14
use strict; use warnings; my @foods = qw(beef karikari beef kandume beef pork pork); #重複排除 + count my %hash; for my $i(@foods){ $hash{$i}++; } for my $i(sort {$hash{$b} <=> $hash{$a}} keys %hash){ print "$i :$hash{$i}\n"; }
1 2 3 4
beef :3 pork :2 kandume :1 karikari :1