I am having trouble figuring out how to create several %th2
structures (see below) each of which will be the values of $th1{0}
, $th1{1}
, and so on.
I am also trying to figure out how to traverse the keys in the second hash %th2
. I am running into that error that is discussed frequently in SO,
Can't use string ("1") as a HASH ref while "strict refs" in use
Also, when I assign %th2
to each key in %th1
, I am assuming this is copied into %th1
as an anonymous hash, and that I am not overriting those values as I re-use %th2
.
use strict;
my %th1 = ();
my %th2 = ();
my $idx = 0;
$th2{"suffix"} = "A";
$th2{"status"} = 0;
$th2{"consumption"} = 42;
$th1{$idx} = %th2;
$idx++;
$th2{"suffix"} = "B";
$th2{"status"} = 0;
$th2{"consumption"} = 105;
$th1{$idx} = \%th2;
for my $key1 (keys %th1)
{
print $key1."\n\n";
for my $key2 (keys %$key1)
{
print $key2->{"status"};
}
#performing another for my $key2 won't work. I get the strict ref error.
}