Chinaunix
标题:
perl 版主 flw 禁止我发言, 管理员帮我回复一个问题, 谢谢啦!!
[打印本页]
作者:
substr函数
时间:
2016-01-03 21:32
标题:
perl 版主 flw 禁止我发言, 管理员帮我回复一个问题, 谢谢啦!!
perl 版主 flw 禁止我发言, 管理员帮我回复一个问题, 谢谢啦!!
http://bbs.chinaunix.net/thread-4216945-2-1.html
回复 17楼 weichangh
就是一个 inline sort 代码简洁一点!!
大神! 我是菜鸟哈。
比如酱紫
完全不用子程序?
代码更清晰,简单,明了。
#!/usr/bin/perl
my %h1 = (
"Portland Panthers" => 10,
"Sunnyvale Sluggers" => 12,
"Chico Wildcats" => 5,
"Stevensville Tigers" => 6,
"Lewiston Blazers" => 11,
"Danville Terriors" => 8,
);
my %h2 = (
"Portland Panthers" => 101,
"Sunnyvale Sluggers" => 121,
"Chico Wildcats" => 51,
"Stevensville Tigers" => 61,
"Lewiston Blazers" => 111,
"Danville Terriors" => 81,
);
for my $k ( sort { $h1{$b} <=> $h1{$a} } keys %h1 ) {
printf "\t%s%5d\n", $k, $h1{$k};
}
for my $k ( sort { $h2{$b} <=> $h2{$a} } keys %h2 ) {
printf "\t%s%5d\n", $k, $h2{$k};
}
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2