You're updating a copy of the hashes.
Fix alternative 1:
sub upd_info { # Create non-reference aliases to arguments. our %paramhash; local *paramhash = shift; our @paramarray; local *paramarray = shift; ... keep rest as is ... }
Fix alternative 2:
sub upd_info { my ($paramshash, $paramarray) = @_; while (($key, $val) = each(%$paramhash)) # added $ { $upd_flg = 0; foreach $item (sort { $a cmp $b } @$paramarray) # added $ { if ($item =~ /^$key\s+(\w+)$/) { $upd_flg = $upd_flg + 1; $paramhash->{$key} .= " $1"; # added -> last; } } if ($upd_flg == 0) { $paramhash->{$key} .= " NONE"; # added -> } }
btw, you're gonna get yourself into trouble sooner or later if you don't tighten the scope of your local variables by using my (my $key; my $val; my $item;, etc) It's best if you use use strict;, which will rightfully complain about these variables.
In reply to Re: sub routine trouble
by ikegami
in thread sub routine trouble
by tc1364
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |