N
n00b
Hello,
I've been trying to program a hash of hashes, where the "sub hashes"
would be created at runtime, but with no luck so far. I don't really
know Perl, and I'm a bit lost with the notation - when to use % and
when just $.
Here's an example of what I'm trying to do - that is, I would want this
to print out the keys and values of the sub-hashes - could somebody
tell me why it doesn't work?
Thanks!
my %master_hash = ();
my $count = 0;
for($count=1; $count<11; $count++)
{
my %sub_hash =
(
key1 => $count,
key2 => $count,
key3 => $count,
);
$master_hash{$count} = %sub_hash;
}
my %temp_hash = ();
while( my ($k, %v) = each %master_hash )
{
print "master key: $k \n";
%temp_hash = %v;
while( my ($kk, $vv) = each %temp_hash )
{
print "sub key: $kk value: $vv\n";
}
}
I've been trying to program a hash of hashes, where the "sub hashes"
would be created at runtime, but with no luck so far. I don't really
know Perl, and I'm a bit lost with the notation - when to use % and
when just $.
Here's an example of what I'm trying to do - that is, I would want this
to print out the keys and values of the sub-hashes - could somebody
tell me why it doesn't work?
Thanks!
my %master_hash = ();
my $count = 0;
for($count=1; $count<11; $count++)
{
my %sub_hash =
(
key1 => $count,
key2 => $count,
key3 => $count,
);
$master_hash{$count} = %sub_hash;
}
my %temp_hash = ();
while( my ($k, %v) = each %master_hash )
{
print "master key: $k \n";
%temp_hash = %v;
while( my ($kk, $vv) = each %temp_hash )
{
print "sub key: $kk value: $vv\n";
}
}