Skip to content

Instantly share code, notes, and snippets.

@sarguru
Created July 12, 2012 10:35
Show Gist options
  • Save sarguru/3097317 to your computer and use it in GitHub Desktop.
Save sarguru/3097317 to your computer and use it in GitHub Desktop.
xmlparser with perl
use strict;
use XML::Simple;
use Data::Dumper;
my $mylog = XMLin('mylog.xml');
my @comparray;
my @unitarray;
my $counter =0;
my $sum =0;
foreach my $metric (@{$mylog->{metric}}) {
my $comp = $metric->{complexity} ;
my $unit = $metric->{unit};
push @comparray,$comp;
push @unitarray,$unit;
$counter = $counter+1;
$sum = $sum+$comp;
}
my $mean = $sum/$counter;
my $comp_counter = 0;
my $comp_limit_counter = 0;
foreach my $comp (@comparray) {
my $highest_comp = @comparray[0];
if ($comp == $highest_comp){
$comp_counter = $comp_counter + 1;
}
if ($comp > 15) {
$comp_limit_counter = $comp_limit_counter + 1;
}
}
print "$comp_counter have same highest comp \n";
print "$comp_limit_counter have comp over 15 \n";
print "The highest complexity @comparray[0]\n";
print "The unit name(s) of the highest complexity are as follows \n";
my $temp_count_unit = 0 ;
while ( $temp_count_unit < $comp_counter ){
print "Unit is of highest cv @unitarray[$temp_count_unit]\n";
$temp_count_unit = $temp_count_unit+1;
}
my $temp_count_limit = 0 ;
while ( $temp_count_limit < $comp_limit_counter ){
print "Unit is over limit @unitarray[$temp_count_limit]\n";
$temp_count_limit = $temp_count_limit+1;
}
print "$counter is counter\n";
print "$sum is the sum\n";
print "$mean is the mean\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment