Dietmar said:
if i have a hash %myhash in, lets say tree arguments, with values
$myhash{$a}{$b}{$c}
then i can get the value-list of the "last"
subhash (fixed 1.,2. args) by
values %{$myhash{bla}{blum}}
Cool!
I'd like to get the list of the "middle" subhash
(fixed 1., 3. args). How is this possible?
If I understand what you're looking for, you want all the values of the
form
$myhash{$a}{XXX}{$c} for all values of XXX. Is that correct?
(Note: It is generally most helpful if you can provide, at minimum, a
sample set of input and desired output. That way, we don't have to
guess as to what you're actually looking for.)
If I have interpreted your desire correctly, there is no particular
built-in way of obtaining this. In fact, I'd take a long hard look at
your data structure, and try to determine if perhaps it should be
redesigned. Regardless, you can obtain this list by looping through
the keys of the %{$myhash{$a}} hash:
my @values;
for my $key (keys %{$myhash{$a}}) {
push @values, $myhash{$a}{$key}{$c} if exists $myhash{$a}{$key}{$c};
}
The additional 'if' modifier is to ensure that each particular hash
does in fact have a key $c. If you are not concerned about this, you
could rewrite this as one 'map' statement[1]:
my @values = map {$myhash{$a}{$_}{$c}} keys %{$myhash{$a}};
Hope this helps,
Paul Lalli
[1] In truth, you could probably keep the 'if exists' logic and still
use a single statement, by adding in a grep() clause. But, IMHO, at
that point it's simply more clear to spell it out with the explicit for
loop.