perl hash的问题,请大家帮助解决!在线等待!

sunauqt 2003-01-07 05:15:18
%test = (
"one" => "100",
"two" => "200",
"three" => "50"
);
while(($index,$value) = each(%test)) {
$msg = "$index---$value\n";
open(FILE,">>test.log");
print FILE $msg;
close FILE;
}
我想把这个HASH按VALUE值从大到小排列后再写入到LOG文件中去,该如何做呢?
...全文
30 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunauqt 2003-01-13
  • 打赏
  • 举报
回复
能解释一下这是什么意思吗?
foreach (sort {$test{$b} <=> $test{$a}} keys %test){
$msg = "$_---$test{$_}\n";
print FILE $msg;
}
tl66 2003-01-08
  • 打赏
  • 举报
回复
%test = (
"one" => "100",
"two" => "200",
"three" => "50"
);
open(FILE,">test.log");
foreach (sort {$test{$b} <=> $test{$a}} keys %test){
$msg = "$_---$test{$_}\n";
print FILE $msg;
}
close FILE;

2,203

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 CGI
社区管理员
  • CGI社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧