in reply to Re^3: printing data structure
in thread printing data structure

The reason I need the [@tmp] notation is because I need to treat each @array as a line of text. I'm working with the Spreadsheet::WriteExcel module. Unfortunately I didn't choose very good example code.

Replies are listed 'Best First'.
Re^5: printing data structure
by ikegami (Patriarch) on Jan 08, 2007 at 20:19 UTC

    hash → key: given name, value: somearray
    somearray → reference to array of families
    family → reference to array of given names

    Not sure how you want it printed.

    use warnings; use strict; my %data; foreach my $string ( 'flinstones,fred,barney,willma,betty', 'flinstones,dino', 'doe,joe,jane', ) { my @family = split(/\s*,\s*/, $string); my $surname = shift @family; push @{$data{$surname}}, [ @family ]; } # use Data::Dumper; # print Dumper(\%data); foreach my $surname (keys %data) { my $somearray = $data{$surname}; foreach my $family (@$somearray) { foreach my $given (@$family) { print("$given $surname\n"); } print("--", "\n"); } }

    outputs

    joe doe jane doe -- fred flinstones barney flinstones willma flinstones betty flinstones -- dino flinstones --