迭代哈希

迭代哈希怎么玩啊。。。数组作为哈希表A的值,哈希表A作为另一哈希表B的值
终于搞定了。。。得记录下 

#!/usr/bin/perl -w


sub gettime
{
 my $line = $_[0];
 my @temptime =split(/timestamp/,$_);
 $temptime[1] =~s/\>//;
 $temptime[1] =~s/\<//;
 $temptime[1] =~s/GMT\///;
 my @temptime2 = split(/\s/,$temptime[1]);
 my @gettime =split(/\:/,$temptime2[1]); 
 my $second = pop(@gettime);
 my @gettime2 = split(/\./,$second);
 push(@gettime,$gettime2[0]); 
 
 return @gettime;
}
sub getid
{
 my $line = $_[0];
 my @temp = split(/submit_id>/,$_);
 my @temp2 =split(/submit/,$temp[1]);
 $temp2[0]=~s/\///;
 $temp2[0]=~s/\<//;
 return $temp2[0];
}
sub main
{
 our @submittime=();
 our @pricetime=() ;
 our $averagetime = 0;
 our $alltime =0;
 our @id =();
 our @priceid =();
 @id = keys our%parsehash;
 our %onehash = values(%parsehash);
 %onehash = ("submittime"=>\@submit,
    "pricetime"=>\@pricetime);
 
 
 our $inputfile = $ARGV[0];
 open(INF,"$inputfile")or die ("can not open $inputfile!\n");
 while(<INF>)
 {
  if(/<submit taker/)
  {
   my @submittime = gettime($_);
   my $tempid = getid($_);
   push(@id,$tempid);
   print "submitid-$tempid $submittime[0]:$submittime[1]:$submittime[2]\n";
   
   $parsehash{$tempid}{"submittime"}=\@submittime;
   $tempid =(); 
   next;
  } 
  elsif(/<price>/)
  {
   my @pricetime = gettime($_);
   my $pid = getid($_);
   print "price---$pid $pricetime[0]:$pricetime[1]:$pricetime[2]\n";
   
   print "111=====we are looking for $pid in hash\n";
   
   if (exists $parsehash{$pid})
   {
    if(exists $parsehash{$pid}{"pricetime"}){print "priceid $pid Exist!!!!!!\n";}
    else
    {
     $parsehash{$pid}{"pricetime"}=\@pricetime;
     print "priceid $pid find match!!!!!!\n";system("pause");
    }
   }
   print "222=====we are looking for $pid in price \n"; 
   my $get = grep(/^$pid$/,@priceid);
   if(!$get)
   {
    push(@priceid,$pid);
    print "response id :$pid ^^^^^^\n";system("pause");
   }
   
   next;
  } 
 }
 close(INF); 
 
 
 my $onetime=0;
 my $number =0;
 foreach my $i(@priceid)
 {
  print "AAAAA $i\n";system ("pause");
  my @a =values ($parsehash{$i}{"submittime"});
  my @b =values ($parsehash{$i}{"pricetime"});
  $onetime =($b[0]-$a[0])*3600+($b[1]-$a[1])*60+($b[2]-$a[2]);
  foreach my$x (@a){print "$x ";}
  print "\n";
  foreach my$y (@b){print "$y ";}
  print "\n";
  
  print "the deal id=$i,time between request and response is $onetime\n";
  system ("pause");
  $alltime +=$onetime;
  $number++;
 }
 $averagetime = $alltime/$number;
 print "averagetime:$averagetime\n";
}
main();

 

向一个函数传递多个参数 我还没搞定。。。。待续。。。。。 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值