D
davidmichaelkarr
I've paged through the docs on arrays and hashes, but I can't find a
clear answer for my situation.
I'm trying to build a hash keyed by a string, where the values are
arrays of hashes. I'll need to add new hashes to the array for
particular keys in the main hash. Later, I'll need to step through the
keys of the main hash and operate on the data in each hash in the
array.
I've tried several variations of this, and it doesn't quite work yet.
Each time I have a new hash to add to the array associated with a key,
I'll need to append the new hash to the end of the array.
I think part of the problem here is that it's not obvious how to add a
hash to the end of an array, without it "opening up" the has into an
array of the keys and values. I think it might require using a
reference to the hash instead, but I'm not sure.
For instance, I figure that the following is a "manual" construction of
a hash holding arrays of hashes, but maybe I'm wrong:
my %testhash = ("abc" => (("xxx" => "yyy"), ("aaa" => "bbb")),
"def" => (("jjj" => "kkk"), ("ppp" =>
"qqq")));
If I try to reference the "abc" key, like this:
print $testhash{"abc"};
it prints "xxx". I'm not certain what that indicates.
clear answer for my situation.
I'm trying to build a hash keyed by a string, where the values are
arrays of hashes. I'll need to add new hashes to the array for
particular keys in the main hash. Later, I'll need to step through the
keys of the main hash and operate on the data in each hash in the
array.
I've tried several variations of this, and it doesn't quite work yet.
Each time I have a new hash to add to the array associated with a key,
I'll need to append the new hash to the end of the array.
I think part of the problem here is that it's not obvious how to add a
hash to the end of an array, without it "opening up" the has into an
array of the keys and values. I think it might require using a
reference to the hash instead, but I'm not sure.
For instance, I figure that the following is a "manual" construction of
a hash holding arrays of hashes, but maybe I'm wrong:
my %testhash = ("abc" => (("xxx" => "yyy"), ("aaa" => "bbb")),
"def" => (("jjj" => "kkk"), ("ppp" =>
"qqq")));
If I try to reference the "abc" key, like this:
print $testhash{"abc"};
it prints "xxx". I'm not certain what that indicates.