Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: passing a hash ref in a sub

by jimpudar (Pilgrim)
on Nov 01, 2018 at 17:13 UTC ( #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
Node Status?
node history
Node Type: note [id://1225064]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2019-12-16 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?