SmokeyB has asked for the wisdom of the Perl Monks concerning the following question:

Hey All!

It might be close to the end of the day, or I just might be losing my head, but I need some help accessing a referenced HASH.

I have a hash called %soapResult which gets populated from a web service.

When I use Data::Dumper on it, I get this result:
$VAR1 = 'VehicleClaimHistoryConsumerDS'; $VAR2 = { 'RequestParametersDT' => { 'VIN' => '1G2JC51H', 'Memo' => '1234567890', 'VICCType' => 'A' }, 'ClaimKindOfLossTransDT' => { 'LossAmt' => '59', 'UITTransactionTypeCode' => '', 'ClaimId' => '070041356250000000 +000', 'Sequence' => '1', 'KindOfLossCode' => '27' }, 'ClaimBaseInfoDT' => { 'VIN' => '1G2JC51H', 'ExpenseAmt' => '0', 'ClaimDay' => '4', 'ClaimYear' => '1993', 'ClaimId' => '070041356250000000000', 'IAOCompanyInd' => 'N', 'ClaimMonth' => '10' }, 'ClaimKindOfLossDT' => { 'VehicleLossCode' => 'K', 'ClaimId' => '070041356250000000000', 'KindOfLossCode' => '27' }, };
I would like to access each one of those hashes inside $VAR2. If anyone has any suggestions, that would be great!!

Cheers,
Smokey

Replies are listed 'Best First'.
Re: Access Hash References
by Ovid (Cardinal) on Sep 15, 2003 at 20:38 UTC

    Accessing them one by one:

    $soapResult{ClaimKindOfLossDT}{ClaimId};

    Accessing them in bulk:

    while (my ($parent_key,$hashref) = each %soapResult) { print "$parent_key:\n"; while (my ($info_key,$value) = each %$hashref) { print "\t$info_key: $value\n"; } }

    Cheers,
    Ovid

    New address of my CGI Course.

      Thanks Ovid! This really helped me out!! Cheers!
Re: Access Hash References
by shenme (Priest) on Sep 15, 2003 at 20:45 UTC
    Wow, you used Data::Dumper to really see the data! You're already smarter than I am on most days.

    You've got a reference to a hash-of-hashes (HoH).   Each value in the first hash is a reference to another hash.

    # $Var2 is a reference to the first-level hash $rh2 = $Var2->{'ClaimBaseInfoDT'}; # $rh2 is now a reference to one of the second-level hashes # contained within the first $claimday = $rh2->{'ClaimDay'}; # which you can use to access the inner-most values # You can do it all in one step, too $claimday = $Var2->{'ClaimBaseInfoDT'}->{'ClaimDay'};