in reply to Passing by reference from within a sub

I believe you want to change sub_c so that it just looks like:

sub sub_c { my %hash1c = @_; print "sub_c arguments: " . Dumper \%hash1c; }

Here's the whole script cleaned up a little:
[05:25][nick:~/monks]$ cat 1134864.pl #! perl use strict; use warnings; use feature qw/ say /; use Data::Dumper; sub sub_b { my %hash1b; $hash1b{'key1'} = 1; say 'calling sub_c from sub_b'; sub_c( %hash1b ); } sub sub_c { my %hash1c = @_; say 'sub_c arguments: ' . Dumper \%hash1c; } say 'calling sub_b'; sub_b(); my %hash1a; $hash1a{'key1'} = 1; say 'calling sub_c directly'; sub_c( %hash1a ); __END__
[05:25][nick:~/monks]$ perl 1134864.pl calling sub_b calling sub_c from sub_b sub_c arguments: $VAR1 = { 'key1' => 1 }; calling sub_c directly sub_c arguments: $VAR1 = { 'key1' => 1 };
The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Passing by reference from within a sub
by arvid (Initiate) on Jul 15, 2015 at 12:35 UTC
    Thank you Nick. Got it working now.