perl滑动匹配
发布时间:2020-12-15 23:53:14 所属栏目:大数据 来源:网络整理
导读:#!/bin/perl my($ansFile,$result) = @ARGV; if($#ARGV 0 ) { print "usage:perl count_time.pl time.txt n"; exit(-1); } open(frecOut,"result_time.txt") or die "3n"; ?open (ansf1,"$ansFile") or die "8n"; ?#以下代码统计答案中的语音总时长 ?$ans
#!/bin/perl
my($ansFile,$result) = @ARGV; if($#ARGV < 0 ) { print "usage:perl count_time.pl time.txt n"; exit(-1); } open(frecOut,">result_time.txt") or die "3n"; ?open (ansf1,"$ansFile") or die "8n"; ?#以下代码统计答案中的语音总时长 ?$answerflag=0; ?$position1=0; ?$dataflag1=0; ?$answer_total=0; ?#单个文件统计时间 ?$answer_total_per=0; #单个文件统计时间 ?$count=0; ?$pre1; ?$pre21; ?$answer_time1; ?$answer_time2; ?$position_change1; ?print "initialization position is $position1n"; ?while($ansfline1=<ansf1>) ? ? #读完一行位置已经是下一行的开始 { #$pre1=$position1; #$position1 = tell(ansf1); chomp($ansfline1); if ($ansfline1 eq ""data"") ? ? { $dataflag1=1; #print "ansfline1 is $ansfline1n"; $position1 = tell(ansf1); print "begin position is $position1n"; next; } $pre1=$position1; $position1 = tell(ansf1); if($dataflag1==1) { ? ? print "position is $position1n"; #print "dataflag1 is $dataflag1 and ?line is $ansfline1n"; if($answerflag==0) { if ( !( $ansfline1 =~ /"/ )) ? { ? $answerflag=1; ? $answer_time1=$ansfline1; ? $pre21=tell(ansf1); ? ? ? } } elsif($answerflag==1) { ? ?if ( ! ( $ansfline1=~/"/ )) ? { ? $answerflag=2; ? $answer_time2=$ansfline1; ? ? ? } else { #$position_minus=$position-$pre; ?seek(ansf1,$pre1,0); ? ? ?#回退1行 ? $position_change1 = tell(ansf1); $position = tell(ansf1); ? ? ? print "position minus 1 is $position_change1n"; ? $answerflag=0; } ? ? } elsif($answerflag==2) { ? if($ansfline1=~ /[x80-xFF]+?/) ? #if($ansfline1=~/"/) ? { ? #print "computen"; ? $count++; ? #print "$count ?$ansfline1n"; ? $answer_total+=$answer_time2-$answer_time1; ? #print(frecOut "find $resfline in $resFile is not match in $ansFilen"); ? } ? else ? { ? ? seek(ansf1,$pre21,0); ? ? #回退两行 ? $position_change1 = tell(ansf1); $position = tell(ansf1); ? ? ? print "position minus 2 is $position_change1n"; ? } ?? ? $answerflag=0; ?? ?? } #if( !( $ansfline=~/"/ ) ) #{ # ?$answer_time1=$ansfline; #} ? ?} ?} ?$answer_total_per=$answer_total; ?print "times is $countn"; ?print(frecOut "times is $countn"); ?print "answer_total_per time is $answer_total_pern"; ?print(frecOut "answer_total_per time is $answer_total_pern"); ? close(ansf1); close(frecOut); test.txt 文本 "data" 75.759 76.746 "哦好谢谢啊" 76.746 78.403625 "嗯那就不打扰了再见" 78.403625 79.2495 "再见" 79.2495 80.384 "*" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |