in reply to problem with variable scoping

parth00:

I don't see your bug, but why not just use something like (untested):

sub populatemessagedefs { my $hashref = shift; my $string = shift; my @list = split(',', $string); while (@list) { my $k = shift @list; my $v = shift @list; $$hashref{$k}=$v unless exists($$hashref{$k}) and $v < += $$hashref{$k}; } my %hash2 = split(',', $string); }

Update 2: I missed the bit where you're keeping the largest value for each key. Corrected code above, original code below.

sub populatemessagedefs { my $hashref = shift; my $string = shift; %$hashref = (%$hashref, split(',',$string)); }

Update: I forgot to mention--you don't want to use a prototype on your subroutine definition.

...roboticus