Created
July 16, 2012 05:50
-
-
Save sarguru/3120903 to your computer and use it in GitHub Desktop.
xml hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use XML::Simple; | |
use Data::Dumper; | |
sub trim($) | |
{ | |
my $string = shift; | |
$string =~ s/^\s+//; | |
$string =~ s/\s+$//; | |
return $string; | |
} | |
my $mylog = XMLin('log.xml'); | |
my %testhash = (); | |
#print Dumper($mylog); | |
foreach my $measure (@{$mylog->{measure}}) { | |
#print Dumper($measure); | |
my $measure_type = $measure->{type}; | |
if ($measure_type eq 'Function'){ | |
#print Dumper($measure); | |
foreach my $item (@{$measure->{item}}) { | |
#print Dumper($item); | |
my $name_test = $item->{test}; | |
my $test_value_raw = (@{$item->{value}}[2]); | |
my $test_value = &trim($test_value_raw); | |
#my $int_test = $test_value+1; | |
# print "$int_test"; | |
$testhash{$name_test} = $test_value; | |
#print "item is $name_test and the third value is $test_value\n"; | |
} | |
} | |
} | |
my $threshold_value = 1; | |
my $key_for_max_value; | |
my $max_value = -1; | |
while ((my $key, my $value) = each %testhash) { | |
if ($value > $max_value) { | |
$max_value = $value; | |
$max_key = $key; | |
} | |
} | |
while (($key_1, $value_1) = each(%testhash)){ | |
if($value_1 >= $max_value) { | |
print "Max values are ". $key_1.", ".$value_1."\n"; | |
} | |
} | |
while (($key_1, $value_1) = each(%testhash)){ | |
if($value_1 >= $threshold_value) { | |
print "threshold values are ". $key_1.", ".$value_1."\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment