您的位置:首页 > 其它

迭代哈希

2012-03-22 13:36 106 查看
迭代哈希怎么玩啊。。。数组作为哈希表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();

向一个函数传递多个参数 我还没搞定。。。。待续。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: