You are already passing a reference. Don't copy it and don't return anything (as your sub is called in void context anyway) and assign the args from @_ instead of shift:
use strict; use warnings; my $captains = "kirkpicard"; my %starship = ( 'EntTOS'=>0, 'EntA'=>0, 'EntD'=>0, 'EntE'=>0, ); trivia ($captains,\%starship); print "Kirk was on Enterprise #: $starship{EntTOS}, $starship{EntA}\ +n"; print "Picard was on Enterprise #: $starship{EntD}, $starship{EntE}\n" +; sub trivia { my ($captains, $starship_ref) = @_; if ($captains =~ m/(kirk)/) { $starship_ref->{'EntTOS'} = 1; $starship_ref->{'EntA'} = 2; } if ($captains =~ m/(picard)/) { $starship_ref->{'EntD'} = 4; $starship_ref->{'EntE'} = 5; } }
In reply to Re: Replacing original hash with modified hash returned from subroutine
by hippo
in thread Replacing original hash with modified hash returned from subroutine
by CommaSplice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |