That is a lot of code for that task, I believe. I couldn't get through all of that to see where the header line would have to printed, so I just quickly hacked out how I would do this:
use strict; use warnings; # Read configuration file my @files; my $filecounter = 1; open (my $config_fh, "<", "config_car.txt") or die "Could not open configuration file: $!\n"; while (<$config_fh>) { next unless /=/; (my $line, my $name) = split (/\s*=\s*/); chomp $name; my $abbr; if ($line =~ /CUR_RESULTS/) { $abbr = "_C0"; } else { $abbr = "_B" . $filecounter++; }; push @files, {"line" => $line, "name" => $name, "abbr" => $abbr}; }; close $config_fh; # Create data from files my %models; foreach my $file (@files) { open (my $fh, "<", $file->{"name"}) or die qq(Could not open file $file->{'name'}: $!\n); my $modelname; while (<$fh>) { m(CAR_model_) and do {(undef, $modelname) = split (/_model_/); chomp $modelname; next; }; m(:) and do {(my $feature, my $value) = split (/\s*:\s*/); chomp $value; $models{$modelname}{$file->{"abbr"}}{$feature} = +$value; next; }; } close $fh; } # Output table my @modelnames = sort keys %models; foreach my $feature (qw(TYRE ENGINE CHASSIS)) { print "Model"; foreach my $file (@files) { printf "%12s%s", $feature, $file->{"abbr"}; # Header line } print "\n"; foreach my $modelname (@modelnames) { print $modelname; foreach my $file (@files) { printf "%15s", $models{$modelname}{$file->{"abbr"}}{$featu +re}; } print "\n"; } print "\n"; }
Note that I eliminated the duplicate headers (you wrote two "B2" headers each time) and put one for the "current case" in instead.
In reply to Re: Not able to construct the header information of multiple files from the table derived from the Hash datastructure (hash is built after parsing the extracted data from text file)
by Svante
in thread Not able to construct the header information of multiple files from the table derived from the Hash datastructure (hash is built after parsing the extracted data from text file)
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |