George_Sherston has asked for the wisdom of the Perl Monks concerning the following question:
Now, say I want to print out everyone's name, ordered first by the key of the "outer" hash and then by the next hash in (i.e. in this case exactly the order you see them above) I tried to do:$VAR1 = { '1' => { '1' => { 'EMail' => 'norbert@thnwb.com', 'Name' => 'Norbert Bodkin' }, '5' => { 'EMail' => 'sue@thnwb.com', 'Name' => 'Sue Soup' } }, '2' => { '3' => { 'EMail' => 'max@thnwb.com', 'Name' => 'Max Grappler' } } };
(line numbers added for clarity) BUT... I get Can't use string ("1") as a HASH ref while "strict refs" in use at /home/htdocs/hosted/thinweb/lib/devbox.pm line 108. I tried a few other lame ways to do it which I won't go into her, but when I RTFMed, I found that my first cut was pretty much the staff solution... as far as I could tell. I even got superstitious and tried106 my $status; 107 for $status (keys %Status) { 108 for (keys %{ $Status{$status} }) { 109 print $Status{$status}{$_}{'Name'}, br; 110 } 111 }
... nada.105 my $status; 106 my $id; 107 for $status (keys %Status) { 108 for $id (keys %{ $Status{$status} }) { 109 print $Status{$status}{$id}{'Name'}, br; 110 } 111 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing a Hash of Hashes
by c-era (Curate) on Nov 17, 2001 at 01:18 UTC | |
|
Re: Accessing a Hash of Hashes
by CubicSpline (Friar) on Nov 17, 2001 at 01:22 UTC | |
|
ACK! ACK! ACK!!
by George_Sherston (Vicar) on Nov 17, 2001 at 01:28 UTC |