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

Hi monks, I am facing a little difficulty in this simple piece of code. Let me just tell you what I am trying to do. I have a hash reference
$result<code>which has the following data <code> $VAR1 = { 'serviceIdList' => { 'serviceId' => [ '3', '4' ] } }; <code> Now how i got that is by executing this statement <code>print Dumper $result;
Now for all the value in the array ref serviceId, I would like to call a function getServiceType which takes serviceId as the argument. This function again returns a hash ref, say, when I pass serviceId=3 as argument, I get a hash ref which contains the following data
$VAR1 = { 'serviceType' => '9', 'maxNrOfRules' => '0', 'defaultRule' => '0' };
Now, the code should be able to check if serviceType is equal to 9, then it should immediately exit, else it should continue for all the elements in the array ref. In case, my scenario is not clear, please let me know. Your help is highly appreciated. Thanks and regards

Replies are listed 'Best First'.
Re: dereferencing array ref in a hash ref
by grizzley (Chaplain) on Jul 17, 2012 at 06:49 UTC
    Something like: @ids = @{ $result->{'serviceIdList'}{'serviceId'} } should put needed values to table @ids.
      Bingo! I have completed my scenario with your help. Thank you very much... :)
      Thanks for making one part of my scenario work. Let me try with the rest. :)
Re: dereferencing array ref in a hash ref
by Gangabass (Vicar) on Jul 17, 2012 at 07:18 UTC
    @ids = @{ $result->{$serviceType}->{$serviceId} }
      You have used scalar variables which doesnt work.