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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.