use warnings; use strict; use Data::Dumper; my ($hashCarRef); my $baselineIndex; my $CurProcessedFile; my (%ConfigInfo,%CarDatabaseLookupTable); ####################### # Main program ####################### ### Call the Function to read the config file and read the path of the file, from where the data has to be read &ParseConfigFile('./config_car.txt',\%ConfigInfo); #### Print the number of baseline files read ######## print "Number of Baselines: $ConfigInfo{'Data'}{'File'}{'Count'}\n"; #### Construct the lookup table from current file and base files which contain reference data &ConstructLookUpTable(\%CarDatabaseLookupTable); print Dumper($hashCarRef); #### Print the current result in table format w.r.t to base files provided in the config file my $FileCount; my $sortid; my $curModelnumber; my ($CarComponent,$CarComponentValue); foreach $sortid (sort {$a <=> $b } keys %{$CarDatabaseLookupTable{'Car'}}) { foreach $curModelnumber (sort {$a <=> $b } keys %{$CarDatabaseLookupTable{'Car'}{$sortid}}) { print "$curModelnumber \t\t"; my $FileCount=0; while ($FileCount <= $ConfigInfo{'Data'}{'File'}{'Count'}) { if($FileCount == 0) { $CurProcessedFile="Current_Results"; } else { $CurProcessedFile="Baseline_"."$FileCount"; } # Format used to construct look up table {'Car'}{id}{$ModelNumber}{$CurProcessedFile}{'TYRE/CHASSIS/ENGINE'} ($CarComponent,$CarComponentValue) = each (%{$CarDatabaseLookupTable{'Car'}{$sortid}{$curModelnumber}{$CurProcessedFile}}); print "$CarComponentValue\t\t"; $FileCount++; } # While loop print "\n"; }# Innert For loop print "\n\n"; } # Outer For loop exit; ###################################################### ########### Function to Construct the look up table ###################################################### sub ConstructLookUpTable { print "ConstructLookUpTable....."; ($hashCarRef) = @_; my $ModelNumber; my $CountIndex=0; while($CountIndex <= $ConfigInfo{'Data'}{'File'}{'Count'}) { if($CountIndex == 0) { # Process first Current Results $CurProcessedFile="Current_Results"; } else { $CurProcessedFile="Baseline_"."$CountIndex"; } print "$CurProcessedFile : $ConfigInfo{'Data'}{$CurProcessedFile}{'Path'}\n"; open FILEDELT, $ConfigInfo{'Data'}{$CurProcessedFile}{'Path'} or die "can't open the file $!\n"; while() { chomp($_); if($_ =~ /CAR_model_(\d+)/) { $ModelNumber = $1; next; } if($_ =~ /TYRE\s*\:\s*(\d+)/) { $hashCarRef->{'Car'}{1}{$ModelNumber}{$CurProcessedFile}{'TYRE'}=$1; next; } if($_ =~ /ENGINE\s*\:\s*(\d+)/) { $hashCarRef->{'Car'}{2}{$ModelNumber}{$CurProcessedFile}{'ENGINE'}=$1; next; } if($_ =~ /CHASSIS\s*\:\s*(\d+)/) { $hashCarRef->{'Car'}{3}{$ModelNumber}{$CurProcessedFile}{'CHASSIS'}=$1; next; } } # End of While $CountIndex++; } # End of While loop to read each file interating through each file close(FILEDELT); print "Done\n"; } ###################################################### ########### Function to Parse the config file ###################################################### sub ParseConfigFile { my ($ConfigFile,$hashRef)=@_; open(CONFIGFILE,"<$ConfigFile") or die $!; my $baselineIndex=0; while() { chomp($_); if(($_ eq '') || ($_ =~ m/^;/)) {next;} if($_ =~ m/CUR_RESULTS=(.*)/) { $hashRef->{'Data'}{'Current_Results'}{'Path'}=$1; # Convert Windows format to Unix Format $hashRef->{'Data'}{'Current_Results'}{'Path'} =~ tr/\\/\//; $hashRef->{'Data'}{'File'}{'Count'}=0; next; } if($_ =~ m/BASE=(.*)/) { $baselineIndex++; $hashRef->{'Data'}{"Baseline_$baselineIndex"}{'Path'}=$1; # Convert Windows format to Unix Format $hashRef->{'Data'}{"Baseline_$baselineIndex"}{'Path'} =~ tr/\\/\//; $hashRef->{'Data'}{'File'}{'Count'}=$baselineIndex; next; } } }