作者turnmood (好人去死去死团员)
看板Perl
标题[问题] Perl条件式判别问题
时间Wed Nov 11 12:41:25 2009
已经将原始log中透过Perl处理成以下格式
09:11:06.845,33066845,Send: msg_length, 73,cQ694,0,
09:11:06.860,33066860,Recv: msg_length, 130,cQ694,0,
09:11:09.355,33069355,Send: msg_length, 73,cQ694,4,
09:11:09.369,33069369,Recv: msg_length, 130,cQ694,4,
其中利用最後一栏数字与Send/Recv做以下判别:
======================================
发送状态1:ExecType=0
发送状态2:ExecType=4
发送状态3:ExecType=5
--------------------------------------
回报状态1:ExecType=0 或ExecType=6
回报状态2:ExecType=4
回报状态3:ExecType=5
======================================
if ( $val_type eq 'Send' && $svals->{ExecType} eq '4' )
{
$buf->{$ordno}{SS}{tp} = $val_ts;
$buf->{$ordno}{SS}{ms} = $val_ms;
}
elsif ( $val_type eq 'Recv' && ( $svals->{ExecType} eq '4') )
{
if ( !defined $buf->{$ordno}{RR} )
{
$buf->{$ordno}{RR}{tp} = $val_ts;
$buf->{$ordno}{RR}{ms} = $val_ms;
}
}
09:11:06.845,33066845,Send: msg_length, 73,cQ694,0,
09:11:06.860,33066860,Recv: msg_length, 130,cQ694,0,
09:11:09.355,33069355,Send: msg_length, 73,cQ694,4,
09:11:09.369,33069369,Recv: msg_length, 130,cQ694,4,
执行Perl分析後产生结果如下:
cQ694, 09:11:09.355 => 09:11:09.369 ( 14)
第4笔-第3笔,Type都是4的 , Recv-Send计算时间差 OK!
=========================================================
09:11:06.845,33066845,Send: msg_length, 73,cQ694,0,
09:11:06.860,33066860,Recv: msg_length, 130,cQ694,0,
09:11:09.355,33069355,Send: msg_length, 73,cQ694,4,
09:11:09.369,33069369,Recv: msg_length, 130,cQ694,4,
**但是要同时区别以下送单 0和4的送单,
改写成目前写法就会出错
if ( ($val_type eq 'Send' && $svals->{ExecType} eq '4') ||
($val_type eq 'Send' && $svals->{ExecType} eq '0') )
{
$buf->{$ordno}{SS}{tp} = $val_ts;
$buf->{$ordno}{SS}{ms} = $val_ms;
}
elsif ( ($val_type eq 'Recv' && $svals->{ExecType} eq '4') ||
($val_type eq 'Recv' && $svals->{ExecType} eq '0') )
{
if ( !defined $buf->{$ordno}{RR} )
{
$buf->{$ordno}{RR}{tp} = $val_ts;
$buf->{$ordno}{RR}{ms} = $val_ms;
}
}
cQ694, 09:11:09.355 => 09:11:06.860 ( -2495)
第3笔-第2笔 ,但是Type不同,错了
且时间不应该负的
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.63.31.120
1F:推 herculus6502:在减的时候要不要顺便判断一下ExecType是否相同呢 11/11 13:10
2F:推 herculus6502:这样说好了,你的键值现在要多了ExecType,不然会有 11/12 08:30
3F:→ herculus6502:0跟4被你当成同一笔拿来减的情况。为何不用SQL? 11/12 08:31
4F:→ turnmood:意思是在Perl中加一段SQL判别? 11/12 08:51
5F:推 herculus6502:应该是说当初这些资料就要先塞到资料库去处理 11/12 09:16
6F:→ herculus6502:逻辑写成STORED PROCEDURES懂的人也比较多 11/12 09:16
7F:→ herculus6502:逻辑改变时改SP就好,不需要动到主程式 11/12 09:18
8F:→ herculus6502:$net=$buf->{$key}{RR}{ms} - $buf->{$key}{SS}{ms} 11/12 09:25
9F:推 herculus6502:这一行并不会帮你抓出同ExecType的,前面也没有作 11/12 09:29
10F:→ herculus6502:外面的回圈也没有用foreach,写法并不太perlish 11/12 09:31
11F:推 herculus6502:眼前的解法就再加一层回圈iterate各种ExecType 11/12 09:36
12F:→ herculus6502:好奇问一下公司的性质是…? 11/12 09:37