Re: [问题] 读取档案的内容

楼主: hws110 ( only you )   2012-11-13 23:45:18
您好
因为最近还有计算总量的需求
所以我将之前的输出到档案
接着再用另一只perl去计算总量
以下为我的程式码
my $number;
my $total;
open (RESULT , "<". $result_file);
while(<RESULT>)
{
if (/Number:\s+(\d+),\s+Kind\s+(\d+),\s+quantity:\s+(\d+)/)
{
$number = $1;
my $qty = $3;
$total->{ $number } += $qty ;
}
print "代号: $number, total: $total->{ $number }\n";
}
close (RESULT);

Links booklink

Contact Us: admin [ a t ] ucptt.com