作者dryman (dryman)
看板Perl
標題Re: [問題] 讀取檔案的內容
時間Wed Nov 14 09:51:15 2012
my %total;
open (RESULT , "<". $result_file);
while(<RESULT>)
{
my ($check, $num, undef, $kind, undef, $qty) = split(/:\s|, /,$_);
$total{ $num } += $qty if $check =~ /Number/;
}
close (RESULT);
print "代號: $_, total: $total{ $_ }\n" for sort keys %total;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.109.16.166
※ 編輯: dryman 來自: 140.109.16.166 (11/14 09:53)
推 hws110:感謝您~不過我將split(/:\s|,改成split(/\s|,才可正常輸出 11/14 21:37
→ hws110:就有抓到我要的值了~ 11/14 21:38