in reply to Re^2: Dereferencing a portion of a hash
in thread Dereferencing a portion of a hash

$report_data{$domain}{$provider} is a hash reference already. This is shown by your data dumper (which shows that it contains hash key/values).

You are then taking the reference to that hash reference by passing it as \$report_data{$domain}{$provider} which makes it a reference to a reference.

Hence, you need to either not pass it that way or dereference it twice.

$,=" : ";$\="\n"; print $_, $$rpt_ref->{$_} for keys %{$$rpt_ref};
--------------
It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs

Replies are listed 'Best First'.
Re^4: Dereferencing a portion of a hash
by THRAK (Monk) on Feb 18, 2005 at 17:12 UTC
    Thanks, I see that now. Although I don't understand how it is a reference at that point. Prior to that point it is declared and I've simply been populating it via:
    my %report_data; ... $report_data{$domain}{$provider}{ok}++;
      You don't understand how $report_data{$domain}{$provider} is a reference?

      If not, if you were to define things all at once it would be like this:

      my %report_data = ( $domain => { $provider => { 'error' => '0', ... # other stuff here } } }


      The reason it's a reference is because you have a scalar value (hash value $report_data{$domain}) pointing to a hash reference.

      From perldoc -f perldata:


      ...
      All data in Perl is a scalar, an array of scalars, or a hash of scalars
      ...
      Although a scalar may not directly hold multiple values, it may contain a reference to an array or hash which in turn contains multiple values.
      ...


      A hash isn't a scalar, it's a hash, but a reference is a scalar, so it can hold that in the value of the hash where the key is $provider.
      --------------
      It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs