lsteele has asked for the wisdom of the Perl Monks concerning the following question:
But Perl doesn't seem to like this at all:#!usr/bin/perl -w use strict; my @names = ("Tom", "Mary", "Nat", "Luke"); my %people; for(my $i=0; $i < @names; $i++) { $people{$names[$i]}={}; $people{$names[$i]}{number}=$i; $people{$names[$i]}{numbx2}=$i*2; } foreach my $key (keys(%people)) { print "\n".$key."\t".$people{$key}{numbx2}."\t".$people{$key}{number}; }
Also if I change the innermost foreach line to read#!usr/bin/perl -w use strict; my @names = ("Tom", "Mary", "Nat", "Luke"); my %people; for(my $i=0; $i < @names; $i++) { $people{$names[$i]}={}; $people{$names[$i]}{number}=$i; $people{$names[$i]}{numbx2}=$i*2; } foreach my $key (keys(%people)) { foreach my $pkey (keys($people{$key})) { print "\n".$key."\t".$people{$key}{$pkey}; } }
foreach my $pkey (keys(%people{$key})) {
(note the change from $ to %) -- which intuitively I would have thought was correct -- I also can't get the program to run.
I have read through the Perl documentation on a hash of hashes, but it's not terribly enlightening. After several infuriating hours I'm well and truly stuck -- any help is greatly appreciated.
Thanks very much.
Luke
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash of hashes problem
by moritz (Cardinal) on Oct 11, 2007 at 13:38 UTC | |
by lsteele (Initiate) on Oct 11, 2007 at 13:50 UTC | |
by ikegami (Patriarch) on Oct 11, 2007 at 14:08 UTC | |
by naikonta (Curate) on Oct 11, 2007 at 23:40 UTC | |
by ikegami (Patriarch) on Oct 12, 2007 at 02:57 UTC | |
|
Re: Hash of hashes problem
by johngg (Canon) on Oct 11, 2007 at 14:32 UTC | |
|
Re: Hash of hashes problem
by ikegami (Patriarch) on Oct 11, 2007 at 14:02 UTC |