Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Dereferencing a portion of a hash

by THRAK (Monk)
on Feb 18, 2005 at 16:37 UTC ( [id://432396]=note: print w/replies, xml ) Need Help??


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

Maybe this is a stupid question, but how is that passing a reference as a reference? Isn't what you've done (which does work) pass a copy of that portion of the hash? Or is it such that when you pass a portion of a hash it automagically passes it as a reference?
  • Comment on Re^2: Dereferencing a portion of a hash

Replies are listed 'Best First'.
Re^3: Dereferencing a portion of a hash
by RazorbladeBidet (Friar) on Feb 18, 2005 at 16:50 UTC
    $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
      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://432396]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-19 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found