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
In reply to Hash of hashes problem by lsteele
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |