Re: [問題] Perl條件式判別問題
#計算Net值的關鍵條件是在下面的Printf有$net那段才對
#謝謝 herculus6502 的提醒,Perl新手第3天上路
#起碼有正確的方向修改了,公司沒人會Perl = = 慘
my ( $hmax, $hmin, $fg, $cnt ) = ( undef, undef, 0, 0 );
$hmax->{value} = 0.001;
$hmin->{value} = 999.999;
$hmax->{ordno} = 'XXXXX';
$hmin->{ordno} = 'ZZZZZ';
$cnt = 0;
my $ggg = undef;
my $hms = undef;
$hms->{gt30} = 0;
$hms->{28_30} = 0;
$hms->{26_28} = 0;
$hms->{24_26} = 0;
$hms->{22_24} = 0;
$hms->{20_22} = 0;
$hms->{19_20} = 0;
$hms->{18_19} = 0;
$hms->{17_18} = 0;
$hms->{16_17} = 0;
$hms->{15_16} = 0;
$hms->{14_15} = 0;
$hms->{13_14} = 0;
$hms->{12_13} = 0;
$hms->{11_12} = 0;
$hms->{10_11} = 0;
$hms->{lt10} = 0;
my $ssum_ms = 0;
my @lkey = keys %$buf;
@lkey = sort @lkey;
my $lmax = scalar( @lkey );
for ( my $i =0 ;$i< $lmax; $i++ )
{
my $key = $lkey[$i];
if ( (!defined $buf->{$key}{RR}{ms})
|| $buf->{$key}{RR}{ms} eq '' )
{
printf("%s, %s => %s (UNKNOW)\n", $key, $buf->{$key}{SS}{tp}, '??:??:??.???' );
}
else
{
my $net = $buf->{$key}{RR}{ms} - $buf->{$key}{SS}{ms};
$ssum_ms += $net;
if ( $net > $hmax->{value} )
{
$hmax->{value} = $net;
$hmax->{ordno} = $key;
}
if ( $net < $hmin->{value} )
{
$hmin->{value} = $net;
$hmin->{ordno} = $key;
}
if ( $net >= myLimit )
{ $ggg->{$key} = $net; }
if ( $net > 30 ) { $hms->{gt30} += 1; }
elsif ( $net > 28 ) { $hms->{28_30} += 1; }
elsif ( $net > 26 ) { $hms->{26_28} += 1; }
elsif ( $net > 24 ) { $hms->{24_26} += 1; }
elsif ( $net > 22 ) { $hms->{22_24} += 1; }
elsif ( $net > 20 ) { $hms->{20_22} += 1; }
elsif ( $net > 19 ) { $hms->{19_20} += 1; }
elsif ( $net > 18 ) { $hms->{18_19} += 1; }
elsif ( $net > 17 ) { $hms->{17_18} += 1; }
elsif ( $net > 16 ) { $hms->{16_17} += 1; }
elsif ( $net > 15 ) { $hms->{15_16} += 1; }
elsif ( $net > 14 ) { $hms->{14_15} += 1; }
elsif ( $net > 13 ) { $hms->{13_14} += 1; }
elsif ( $net > 12 ) { $hms->{12_13} += 1; }
elsif ( $net > 11 ) { $hms->{11_12} += 1; }
elsif ( $net > 10 ) { $hms->{10_11} += 1; }
else { $hms->{lt10} += 1; }
#看來關鍵條件是在這邊才對
printf("%s, %s => %s (%6d)\n", $key, $buf->{$key}{SS}{tp}, $buf->{$key}{RR}{tp}
, $net );
$cnt++;
}
}
print '-' x 80;print "\n";
printf ("MAX: %s (%.3f)\n", $hmax->{ordno}, $hmax->{value} );
printf ("MIN: %s (%.3f)\n", $hmin->{ordno}, $hmin->{value} );
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.63.31.120
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
5
12
Perl 近期熱門文章
PTT數位生活區 即時熱門文章
10
113