You need to use the sub keyword when declaring/defining subroutines. Here's a working version based on your code.
use strict; use warnings; my (%hash); $hash{'id1'} = "1"; doSub1 (\%hash); # the return id2 should be changed within doSub2 when doSub1 call it. print "$hash{'id2'}\n"; sub doSub1 { # accept param as hash by reference my ($hrec_ref) = @_; $$hrec_ref{'id2'} = "0"; # doSub2(\$hrec_ref{'id2'}); Return Error. Not valid. (works for me - +Hippo) doSub2 (\$hrec_ref->{'id2'}); } sub doSub2 { # handle only a single string param by reference my ($href) = @_; $$href = "value changed in doSub2"; }
In reply to Re^3: Sub hash param by reference
by hippo
in thread Sub hash param by reference
by hankcoder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |