M
Mothra
Hi All,
I am trying to print out a report using a Hash of Hashes and am having
trouble
getting the columns to print out correctly. I have an array that contains
the column
headings in the correct order but I am stuck as how to get the HoH to use
this information. I have provided a test script as to what I have tried.
How can I get the script to print the columns in the correct order.
Thanks
Mothra
#!/app/perl5.8.0/bin/perl
use strict;
use warnings;
my @family = qw(UNIGRAPHICS_NX UNIGRAPHICS SOLID_EDGE WEBTOOLS other);
my %people = (
'wattsl' => {
'SOLID_EDGE' => 3,
'WEBTOOLS' => 10,
'UNIGRAPHICS' => 19,
'UNIGRAPHICS_NX' => 57
},
'friasd' => {
'other' => 2,
'SOLID_EDGE' => 10,
'WEBTOOLS' => 25,
'UNIGRAPHICS' => 21,
'UNIGRAPHICS_NX' => 81
},
'yamaguch' => {
'other' => 4,
'SOLID_EDGE' => 12,
'WEBTOOLS' => 11,
'UNIGRAPHICS' => 9,
'UNIGRAPHICS_NX' => 56
},
'jung' => {
'other' => 2,
'SOLID_EDGE' => 5,
'WEBTOOLS' => 16,
'UNIGRAPHICS' => 13,
'UNIGRAPHICS_NX' => 39
},
'riches' => {
'other' => 2,
'SOLID_EDGE' => 18,
'WEBTOOLS' => 24,
'UNIGRAPHICS' => 10,
'UNIGRAPHICS_NX' => 83
},
);
printf "%24s %10s %10s %8s %5s \n", @family;
foreach my $person( sort keys %people ) {
printf "%9s %2d %2d %2d %2d %2d\n", $person,
map { $people{$person}{$_} } sort keys %{ $people{$person} };
}
I am trying to print out a report using a Hash of Hashes and am having
trouble
getting the columns to print out correctly. I have an array that contains
the column
headings in the correct order but I am stuck as how to get the HoH to use
this information. I have provided a test script as to what I have tried.
How can I get the script to print the columns in the correct order.
Thanks
Mothra
#!/app/perl5.8.0/bin/perl
use strict;
use warnings;
my @family = qw(UNIGRAPHICS_NX UNIGRAPHICS SOLID_EDGE WEBTOOLS other);
my %people = (
'wattsl' => {
'SOLID_EDGE' => 3,
'WEBTOOLS' => 10,
'UNIGRAPHICS' => 19,
'UNIGRAPHICS_NX' => 57
},
'friasd' => {
'other' => 2,
'SOLID_EDGE' => 10,
'WEBTOOLS' => 25,
'UNIGRAPHICS' => 21,
'UNIGRAPHICS_NX' => 81
},
'yamaguch' => {
'other' => 4,
'SOLID_EDGE' => 12,
'WEBTOOLS' => 11,
'UNIGRAPHICS' => 9,
'UNIGRAPHICS_NX' => 56
},
'jung' => {
'other' => 2,
'SOLID_EDGE' => 5,
'WEBTOOLS' => 16,
'UNIGRAPHICS' => 13,
'UNIGRAPHICS_NX' => 39
},
'riches' => {
'other' => 2,
'SOLID_EDGE' => 18,
'WEBTOOLS' => 24,
'UNIGRAPHICS' => 10,
'UNIGRAPHICS_NX' => 83
},
);
printf "%24s %10s %10s %8s %5s \n", @family;
foreach my $person( sort keys %people ) {
printf "%9s %2d %2d %2d %2d %2d\n", $person,
map { $people{$person}{$_} } sort keys %{ $people{$person} };
}