perl滑动匹配

#!/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 "3\n";
 open (ansf1, "$ansFile") or die "8\n";
 #以下代码统计答案中的语音总时长
 $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 $position1\n";
 while($ansfline1=<ansf1>)     #读完一行位置已经是下一行的开始
{
#$pre1=$position1;
#$position1 = tell(ansf1);
chomp($ansfline1);

if ($ansfline1 eq "\"data\"")
    {
$dataflag1=1;
#print "ansfline1 is $ansfline1\n";
$position1 = tell(ansf1);
print "begin position is $position1\n";
next;
}
$pre1=$position1;
$position1 = tell(ansf1);

if($dataflag1==1)
{
    print "position is $position1\n";
#print "dataflag1 is $dataflag1 and  line is $ansfline1\n";
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_change1\n";
  $answerflag=0;
}


   
}
elsif($answerflag==2)
{
  if($ansfline1=~ /[\x80-\xFF]+?/)
  #if($ansfline1=~/\"/)
  {
  #print "compute\n";
  $count++;
  #print "$count  $ansfline1\n";
  $answer_total+=$answer_time2-$answer_time1;
  #print(frecOut "find $resfline in $resFile is not match in $ansFile\n");
  }
  else
  {
 
  seek(ansf1, $pre21, 0);     #回退两行
  $position_change1 = tell(ansf1);
$position = tell(ansf1);
   
  print "position minus 2 is $position_change1\n";


  }
  
  $answerflag=0;
  
  
}
#if( !( $ansfline=~/"/ ) )
#{
#  $answer_time1=$ansfline;
#}

   }
 }
 $answer_total_per=$answer_total;
 print "times is $count\n";
 print(frecOut "times is $count\n");
 print "answer_total_per time is $answer_total_per\n";
 print(frecOut "answer_total_per time is $answer_total_per\n");
 
close(ansf1);

close(frecOut);


test.txt 文本

"data"
0
80.384
25
0
10.477281604089555
"*"
10.477281604089555
11.25975
"喂"
11.25975
13.572678224864765
"*"
13.572678224864765
14.642124999999998
"啊什么事啊"
14.642124999999998
24.293374999999998

75.759
76.746
"哦好谢谢啊"
76.746
78.403625
"嗯那就不打扰了再见"
78.403625
79.2495
"再见"
79.2495
80.384
"*"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值