For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > August 2005 > Anonymous array of hashes question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Anonymous array of hashes question
Jason Normandin

2005-08-04, 5:00 pm

Hello

I have a situation where I build an anonymous array of hashes for some requests and responses found in a file (there can be multiple requests and responses). It works very nicely and tracks all of the responses and requests from an ip to another IP addres
s.

Here is my code:

my $time=$1 if /^(\d+:\d+:\d+\.\d+)/;
my $source=$1 if /(\S+) -> \S+/;
my $destination=$1 if /\S+ -> (\S+)/;
my $sourcePort=$1 if /S=(\d+)/;
my $destinationPort=$1 if /D=(\d+)/;
my $sequenceNumber=$1 if /Sequence number: (\d+)/;

if ($protocol =~ /PING REQUEST/) {
push @{$pingRequests{$destination}}, {
time => $time,
sequenceNumber=>$sequenceNumber
};
}
elsif ($protocol =~ /PING RESPONSE/) {
push @{$pingResponses{$source}}, {
time => $time,
sequenceNumber=>$sequenceNumber
};
}

I can then access the contents via code like:

foreach my $record(@{$pingRequests{$request}}) {
$requestCount++;
print "\tRequest Time=$record->{time}\n" if defined $details;
}

What I want to do however is track the response time between a request and response. This would be identified by the same sequence number for a request/respone pair. I would like to take the time value for each and subtract the response time from the requ
est time to get the response time and add that to the response hash.

I cannot figure out how to access the contents of the anonymous hash for that one value.

Sudo code would be:

elsif ($protocol =~ /PING RESPONSE/) {
responseTime=pingRequests{$source}->time - pingResponses{$destination)->time if pingRequests{$source}->sequenceNumber = pingResponses{$destination}->sequenceNumber;

push @{$pingResponses{$source}}, {
time => $time,
sequenceNumber=>$sequenceNumber
responseTime=>$responseTime

};
}

DOes that make any sense? Can I do what I am trying to accomplish using the logic above? If so, what is that syntax?

Help!

Thanks!
Jason

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com