Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: passing a hash ref in a sub

by jimpudar (Pilgrim)
on Nov 01, 2018 at 17:13 UTC ( [id://1225064]=note: print w/replies, xml ) Need Help??


in reply to Re: passing a hash ref in a sub
in thread passing a hash ref in a sub

Fantastic explanation! The best documentation I have been able to find about this is perlsub, but I would love to see any more details if you have them.

Here is the OP's code working as he expected:

perl -e ' > use strict; > use warnings; > use Data::Dumper; > > my $data = {status=>"ok","message-type"=>"member","message-version"= +>"1.0.0"}; > my $result_hr; > > unfold_hash($data, $result_hr); > print Dumper $result_hr; > > sub unfold_hash { > for my $k ( keys %{ $_[0] } ) { > $_[1]{$k} = $_[0]{$k}; > } > print "unfold_hash ", $_[1] ? scalar %{ $_[1] } : 0, "\n"; > } > ' unfold_hash 3 $VAR1 = { 'message-version' => '1.0.0', 'message-type' => 'member', 'status' => 'ok' };

πάντων χρημάτων μέτρον έστιν άνθρωπος.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found