Re: [問題] 取百分比問題

看板Perl作者 (蜥蜴)時間17年前 (2007/12/07 21:47), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串4/4 (看更多)
沒人要改寫,我沒事來幫忙吧,盡量不改你的程式,加入幾行來達成, 沒有跑過,不保證能用 ※ 引述《iswearwang (^_^)》之銘言: $input_file = $ARGV[0]; $output_file = $ARGV[1]; $output_file_not_exst = 0; open (INPUT_H, "$input_file"); open (OUTPUT_H, "$output_file"); while($_ = <INPUT_H>) { push(@first_trigger, $_); } while($_ = <OUTPUT_H>) { push(@second_trigger, $_); } my $allsum=0; $allsum+= (/=([\d ]*):/)?$1:0 foreach (@first_trigger); #累加第一個檔 $allsum+= (/=([\d ]*):/)?$1:0 foreach (@second_trigger); #累加第二個檔 close(OUTPUT_H); open (FILE, ">$output_file"); for ($j=0;$j<@second_trigger;$j++) { @t = split ' = ', $second_trigger[$j]; $second_bin = $t[0]; @t2 = split ' : ', $t[1]; $second_count = $t2[0]; for ($k=0;$k<@first_trigger;$k++) { @m = split ' = ', $first_trigger[$k]; $first_bin = $m[0]; @m2 = split ' : ', $m[1]; $first_count = $m2[0]; if ( $second_bin =~ m/\(/ ) { if ($second_bin eq $first_bin) { $k=9000; $second_count = $second_count + $first_count; $sum += $second_count; #$second_trigger[$j] = "$second_bin = $second_count : 0.00"; print FILE "$second_bin = $second_count : "; print FILE sprintf("%.2f",$second_count/$allsum),$/; } # match } # bin match } # for #print OUTFILE_H $second_trigger[$j]; } close(FILE); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.173.88

12/07 21:47, , 1F
再強調一次~沒跑過不保證能跑喔
12/07 21:47, 1F
文章代碼(AID): #17MKxoeU (Perl)
文章代碼(AID): #17MKxoeU (Perl)