in reply to Transferring local hashes to module subroutines
%var - Hash $var{$key} - Hash element $var - Scalar. No relation to %var
Excerpt from your code:
return &Y::module_subroutine($hash_to_send); sub module_subroutine { my($hash) = @_; return "The colour of the sky is ". $hash{third_colour}; }
Fix 1:
return &Y::module_subroutine(%hash_to_send); <--- Use the right var sub module_subroutine { my(%hash) = @_; <--- Use the right type return "The colour of the sky is ". $hash{third_colour}; }
The above copies the entire hash (%hash = %hash_to_send;). To avoid that cost, a reference is usually passed. Fix 2:
return &Y::module_subroutine(\%hash_to_send); <--- Pass reference sub module_subroutine { my($hash) = @_; <--- A ref to a hash return "The colour of the sky is ". $hash->{third_colour}; <--- Must dereference }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Transferring local hashes to module subroutines
by cowgirl (Acolyte) on Aug 06, 2008 at 14:27 UTC | |
by EvanK (Chaplain) on Aug 06, 2008 at 14:45 UTC | |
by ikegami (Patriarch) on Aug 06, 2008 at 19:11 UTC | |
by dHarry (Abbot) on Aug 06, 2008 at 14:38 UTC |