- 论坛徽章:
- 307
|
本帖最后由 sunzhiguolu 于 2015-12-27 16:21 编辑
回复 1# weichanghe2000
our %hCourses;
my (%courses, %courses1);
sub desc_sort_subject {
$hCourses{$b} <=> $hCourses{$a}; # Numeric sort descending
}
%courses = (
"Portland Panthers" => 10,
"Sunnyvale Sluggers" => 12,
"Chico Wildcats" => 5,
"Stevensville Tigers" => 6,
"Lewiston Blazers" => 11,
"Danville Terriors" => 8,
);
%courses1 = (
"Portland Panthers" => 101,
"Sunnyvale Sluggers" => 121,
"Chico Wildcats" => 51,
"Stevensville Tigers" => 61,
"Lewiston Blazers" => 111,
"Danville Terriors" => 81,
);
foreach my $key (sort desc_sort_subject keys {%hCourses = %courses} ) {
printf "\t%s%5d\n", $key, $hCourses{"$key"};
}
foreach my $key (sort desc_sort_subject keys {%hCourses = %courses1} ) {
printf "\t%s%5d\n", $key, $hCourses{"$key"};
}
|
|