SPUG:Reference question
Adam Monsen
adamm at wazamatta.com
Sun Mar 9 16:38:03 CST 2003
Thane Williams wrote:
> Ok, maybe someone can point out the obvious to me here. Here's my code:
[...]
What everyone else said was right (package vs. lexical and always use
strict). I'd also suggest /not/ hardcoding "age" and "sex" in your inner
loop. Also, if you initialize the whole hash at once, write it out so
your data structure is very clear.
#!/usr/bin/perl -w
use strict;
my %records = (
Wilma => { age => 32, sex => "female" },
Fred => { age => 38, sex => "male" },
);
foreach my $name (keys %records) {
my $person = $records{$name};
foreach my $trait (keys %$person) {
print "$trait for $name is $person->{$trait}\n";
}
}
--
Was I helpful? Let others know:
http://svcs.affero.net/rm.php?r=meonkeys&p=Default
More information about the spug-list
mailing list