in reply to printing data structure

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

foreach my $surname (keys %data) { my $family = $data{$surname}; foreach my $given (@$family) { print("$given $surname\n"); } }

Giving meaningful names helps. Creating variables in order to use meaninful names helps. $key, $value and @tmp are bad names.

By the way, when using Dumper, it's best if you pass a scalar. print Dumper(\%data);

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

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