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

hmmm...I'm still getting the arrayref when using this:
... use Data::Dumper; print Dumper(\%data); foreach my $surname (keys %data) { my $family = $data{$surname}; foreach my $given (@$family) { print("$given $surname\n"); } }
Produces:
$VAR1 = { 'flinstones' => [ [ 'fred', 'barney', 'willma', 'betty' ] ] }; ARRAY(0x2254d8) flinstones
Am I missing something?

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

    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.

      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 --
      Yoy're correct, I don't need the []. Thanks for all the help