%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 }
In reply to Re: Transferring local hashes to module subroutines
by ikegami
in thread Transferring local hashes to module subroutines
by cowgirl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |