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

Are you sure you want
push @{$data{$key}}, [@tmp];
I thought you did
push @{$data{$key}}, @tmp;

If you really do want
push @{$data{$key}}, [@tmp];
what's the extra level represent?
Names help.

Replies are listed 'Best First'.
Re^4: printing data structure
by Anonymous Monk on Jan 08, 2007 at 20:15 UTC
    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.

      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 --
Re^4: printing data structure
by Anonymous Monk on Jan 08, 2007 at 20:03 UTC
    Yoy're correct, I don't need the []. Thanks for all the help