Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello perl monks.
I had written a script to show this
display as thus:my $Hash = { "A" => ["HYU"], "B" => ["TU6"], "C" => [ "11", "09", "88", "2" ], "D" => [ "01", "11" ] };
A, B, C, D HYU TU6 11 01 09 11 88 2
Thanksuse warnings; use strict; my $Hash = { "A" => ["HYU"], "B" => ["TU6"], "C" => [ "11", "09", "88", "2" ], "D" => [ "01", "11" ] }; # get headiing print join( ",\t" => sort keys %$Hash ), $/; # get the value with the highest numbers of element my $highest_item = 0; foreach ( keys %{$Hash} ) { my $value = scalar @{ $Hash->{$_} }; $highest_item = $value if $highest_item < $value; } # re-write the data given as AoA, with data needed my @final_data; foreach my $key ( sort keys %{$Hash} ) { push @final_data => [ map { $Hash->{$key}[$_] || qq[] } 0 .. ( $highest_item - 1 ) ] +; } # print out in expected output foreach my $pos ( 0 .. $#final_data ) { foreach ( 0 .. $highest_item - 1 ) { print $final_data[$_][$pos], "\t"; } print $/; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can this script be Optimized?
by kcott (Archbishop) on May 01, 2014 at 07:01 UTC | |
by tobyink (Canon) on May 01, 2014 at 08:00 UTC | |
by kcott (Archbishop) on May 01, 2014 at 09:03 UTC | |
by tobyink (Canon) on May 01, 2014 at 23:14 UTC | |
by kcott (Archbishop) on May 01, 2014 at 23:44 UTC | |
by RonW (Parson) on May 01, 2014 at 16:40 UTC | |
by kcott (Archbishop) on May 01, 2014 at 17:03 UTC | |
by RonW (Parson) on May 01, 2014 at 17:22 UTC | |
by kcott (Archbishop) on May 01, 2014 at 18:51 UTC | |
|
Re: Can this script be Optimized?
by NetWallah (Canon) on May 01, 2014 at 05:49 UTC | |
by Anonymous Monk on May 01, 2014 at 06:11 UTC | |
by NetWallah (Canon) on May 01, 2014 at 06:32 UTC |