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' };
πάντων χρημάτων μέτρον έστιν άνθρωπος.
|
|---|