Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: how do I use a hash of hashes reference to a function ?

by Fastolfe (Vicar)
on Sep 22, 2000 at 02:28 UTC ( #33577=note: print w/replies, xml ) Need Help??


in reply to how do I use a hash of hashes reference to a function ?

You may wish to wrap your code in <code> tags next time. I'm not 100% sure what you're asking, but perhaps this code example will answer your question:
sub function { my $hashref = shift; $hashref->{three} = 3; } my %hash = ( one => 1, two => 2 ); &function(\%hash); print join(", ", keys %hash); # one, two, three
You can also have the same behavior like this:
sub function (%) { my %hashref = shift; ... } &function(%hash); # passes %hash as a ref
Then there's this:
sub function { my %hash = %{shift}; # de-references $hash{three} = 3; # Does not affect the real %hash! }

Replies are listed 'Best First'.
RE: Answer: how do I use a hash of hashes reference to a function ?
by Fastolfe (Vicar) on Sep 22, 2000 at 02:31 UTC
    Sorry, I neglected to read your title very well and did not take this one step further:
    %hash = ( one => { a => 10, b => 20 }, two => { c => 30, d => 40 } ); &function(\%hash); sub function { my $hash = shift; $hash->{two}->{d} = 50; # changes 'd' }
    You can go as deep as you want here with hashes of hashes of hashes. Hope that helps...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2020-10-25 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (248 votes). Check out past polls.

    Notices?