Model TYRE_B1 TYRE_B2 TYRE_B2 TYRE_B3 100 10 15 16 19 200 20 25 17 30 300 25 26 18 38 Model ENGINE_B1 ENGINE_B2 ENGINE_B2 ENGINE_B3 100 101 102 103 105 200 301 302 303 305 300 401 402 403 405 Model CHASSIS_B1 CHASSIS_B2 CHASSIS_B2 CHASSIS_B3 100 401 402 403 405 200 501 502 503 505 300 601 602 603 605 #### 100 10 15 16 19 200 20 25 17 30 300 25 26 18 38 100 101 102 103 105 200 301 302 303 305 300 401 402 403 405 100 401 402 403 405 200 501 502 503 505 300 601 602 603 605 #### File name: config_car.txt CUR_RESULTS=C:\car_data.txt BASE=C:\car_data1.txt BASE=C:\car_data2.txt BASE=C:\car_data3.txt #### Current file used to compare against different provided files: car_data.txt CAR_model_100 TYRE : 10 ENGINE : 101 CHASSIS : 401 CAR_model_200 TYRE : 20 ENGINE : 301 CHASSIS : 501 CAR_model_300 TYRE : 25 ENGINE : 401 CHASSIS : 601 #### CAR_model_100 TYRE : 15 ENGINE : 102 CHASSIS : 402 CAR_model_200 TYRE : 25 ENGINE : 302 CHASSIS : 502 CAR_model_300 TYRE : 26 ENGINE : 402 CHASSIS : 602 #### CAR_model_100 TYRE : 16 ENGINE : 103 CHASSIS : 403 CAR_model_200 TYRE : 17 ENGINE : 303 CHASSIS : 503 CAR_model_300 TYRE : 18 ENGINE : 403 CHASSIS : 603 #### CAR_model_100 TYRE : 19 ENGINE : 105 CHASSIS : 405 CAR_model_200 TYRE : 30 ENGINE : 305 CHASSIS : 505 CAR_model_300 TYRE : 38 ENGINE : 405 CHASSIS : 605 #### 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; } } }