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

Hello, In the following output of Dumper:
./getstreet.pl 6045 CK $VAR1 = 'paging'; $VAR2 = bless( { 'maxresults' => '500', 'numpages' => '1', 'numresults' => '1', 'curpage' => '1', 'perpage' => '10' }, 'ResultInfo' ); $VAR3 = 'extra'; $VAR4 = bless( { 'lettercombinatie' => 'CK', 'wijkcode' => '6045', 'provincie' => '', 'reeksindicatie' => '', 'plaats' => '', 'toevoeging' => '', 'huisnr' => '0', 'straat' => '', 'gemeente' => '' }, 'SearchParts' ); $VAR5 = 'results'; $VAR6 = [ bless( { 'straatnaam_nen' => 'Heinsbergerweg', 'lettercombinatie' => 'CK', 'gemeentecode' => '957', 'plaatsnaam' => 'ROERMOND', 'reeksindicatie' => '1', 'provincienaam' => 'Limburg', 'plaatsnaam_extract' => 'ROER', 'straatnaam_ptt' => 'HEINSBERGERWG', 'straatnaam_extract' => 'HEINS', 'plaatsid' => '1077', 'gemeentenaam' => 'ROERMOND', 'gemeenteid' => '321', 'wijkcode' => '6045', 'huisnr_van' => '130', 'straatid' => '146170', 'provinciecode' => 'K', 'huisnr_tm' => '188', 'reeksid' => '401688', 'straatnaam' => 'Heinsbergerweg', 'cebucocode' => '471', 'plaatsnaam_ptt' => 'ROERMOND' }, 'PCReeks' ) ];

The First 2 hashed array can i use with the following statement(for example): $result->{ $login }->{ 'wijkcode' }; (where login is paging or extra).

The third array witch should be a normal array, i can't access. if have tried many different statements like print %{$result}->{results}straatnaam;

But am not able to get the result i hoped for. Does anybody see what i have missed?

Replies are listed 'Best First'.
Re: Hash hashed array with normal array
by moritz (Cardinal) on Sep 20, 2011 at 13:23 UTC

    When you see bless({...}, 'SomeClass') in the output, it means that you have an object of type SomeClass.

    You shouldn't just poke into its internals, but rather the documentation of that class on how to access it, often there are accessor methods defined that you should use instead.

Re: Hash hashed array with normal array
by jethro (Monsignor) on Sep 20, 2011 at 13:19 UTC

    print $result->{'results'}[0]{'reeksid'} would print "401688". Your problem is that you have a one-element array where the only element 0 points to a hash with the data.

      But  $result seems to have been in fact the hash  %result originally and not a reference to a hash, so the statement
          print $result{'results'}[0]{'reeksid'};
      is what would print '401688'.

      The dump of the OP looks like it came from a statement like
          print Dumper %result;
      originally (Update: unless maybe it was something like
          print Dumper %$result;
      which is starting to seem more likely now I think of it and especially in light of the "It works..." comment from hvha above)
      .

Re: Hash hashed array with normal array
by Anonymous Monk on Sep 20, 2011 at 13:16 UTC
    $result->{'results'}[0]{'straatnaam'};

    The value on the results key is an arrayref, not a hashref!

      Thanks!!

      for the fast response!!!

      It works, (but you already know) :)