> -----Original Message-----
> From: Barry Jones [mailto:[EMAIL PROTECTED]]
> Sent: Friday, May 24, 2002 6:32 AM
> To: Beginners @ Perl (E-mail)
> Subject: Getting through a deep hash
>
>
> I'm having trouble with this set of code. I'm trying to
> navigate my way
> through a VERY deep hash (aka hash with references to hash with
> references to arrays with references to hashes, which may not contain
> any values cause that's the way it was written before I got here).
> Anyway, this is not supposed to be flexible in any way, I'm
> just trying
> to hard code my way down to the bottom of the hash set just to prove I
> can get there.
>
> I'm having a problem on the line where the ### is present. I haven't
> been able to see the keys from the hash referenced by
> $spot->{$key}. So
> far I have tried several things to get to them, listed under
> the code.
>
>
> my $results = $test->{testing_results}{testing_result};
> if(ref($results) eq 'ARRAY') {
> for my $spot (@$results) {
> for my $key (keys %$spot) {
> if (ref($spot->{$key}) eq 'HASH') {
> if($key eq 'value_group') {
> ###my %vg = $spot->{$key};
> $result .= $key . "<br>";
> }
> }
> }
> }
> }
>
> Previous attempts:
> for my $morekeys (keys $spot->{$key}) {}
> for my $morekeys (keys %$spot->{$key}) {}
> for my $morekeys (keys %($spot->{$key})) {}
> for my $morekeys (keys (%$spot->{$key})) {}
>
> and as you can see in the line with the ### I was just trying
> to put it
> into a new hash, but that is giving me this error:
> Reference found where even-sized list expected
If $spot->{$key} is a reference to a hash, then you
get to the actual hash by dereferencing:
%{$spot->{$key}}
So, to assign:
my %vg = %{$spot->{$key}};
Or to iterate over the keys:
for my $morekey (keys %{$spot->{$key}}) { ... }
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]