in reply to Passing by reference from within a sub
Isn't this just an ordering issue ?
The compiler hasn't seen the definition for sub_c when it compiles sub_b, but it has by the time it gets to the stand alone call of sub_c, hence the differing behaviour. So if you swap the order of your functions it will do what you want.
use strict; use Data::Dumper; sub sub_c (\%) { my ($hash1c) = @_; print "sub_c arguments:" . Dumper (@_); } sub sub_b () { my %hash1b = (); $hash1b{"key1"} = "1"; print "calling sub_c from sub_b\n"; sub_c (%hash1b); } my %hash1a = (); $hash1a{"key1"} = "1"; print "calling sub_b\n"; sub_b (); print "\n"; print "calling sub_c directly\n"; sub_c (%hash1a);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing by reference from within a sub
by arvid (Initiate) on Jul 15, 2015 at 12:25 UTC |