> -----Original Message-----
> From: Ian [mailto:pcs...@gmail.com] 
> Sent: Thursday, August 27, 2009 11:43
> To: beginners@perl.org
> Subject: Printing a hash of hashes of arrays
> 
> Pure beginners question.
> 
> I'm creating a hash of arrays like this :
> 
> $ihash{$3}{$1} = [...@itab];
> 
> For now I was able to get the data using Dumper but I need to create a
> "pretty" report.
> 
> How do I loop over this hash/hash of arrays to print it out?
        You did not give any real details as to what the data would look
like other than hash and array. What is in the array? Numbers? Alpha?
AlphaNumic?

        Here is a shot which is very simplistic:
#!/usr/bin/perl

use strict;
use warnings;

my %ihash = ();
$ihash{a}{a} = [1,2,3,4,5];
$ihash{a}{b} = [2,3,4,5,6];
$ihash{b}{a} = [3,4,5,6,7];

my $wrkkeya;
my $wrkkeyb;

for $wrkkeya (sort keys %ihash) {
    for $wrkkeyb ( sort keys %{$ihash{$wrkkeya}} ) {
        printf "%-3s%-3s ",
                                $wrkkeya,
                                $wrkkeyb;
                                
        for (@{$ihash{$wrkkeya}{$wrkkeyb}} ) {
            printf "%3d", $_;
         }
        print "\n";
     }
 }
Output:
a  a     1  2  3  4  5
a  b     2  3  4  5  6
b  a     3  4  5  6  7
        
        A start...
         If you have any questions and/or problems, please let me know.
         Thanks.
 
Wags ;)
David R. Wagner
Senior Programmer Analyst
FedEx Freight Systems
1.719.484.2097 Tel
1.719.484.2419 Fax
1.408.623.5963 Cell
http://fedex.com/us 


> 
> 
> Thank you.
> 
> -- 
> Ian
> 

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to