sub PutShare { print "Args: ", join(' | ', @_), "\n"; my $shr = shift; my $shrref = ref $shr; while ($shrref eq 'REF') { print " Dereferencing $shr "; $shr = $$shr; print "to get $shr\n"; $shrref = ref $shr } if (@_ > 1) { my $key = shift; print " Key = $key\n"; if ($shrref eq 'ARRAY') { print " Adding/using '$key' of existing array.\n"; PutShare(\($shr->[int($key)]), @_) } elsif ($shrref eq 'HASH') { print " Adding/using '$key' of existing hash.\n"; PutShare(\$shr->{$key}, @_) } elsif ($key =~/^\s[-+]?\d+/) { my $new = &share([]); print " Adding '$key' to new array.\n"; PutShare(\$new->[int($key)], @_); $$shr = $new } else { my $new = &share({}); print " Adding '$key' to new hash: $new\n"; PutShare(\$new->{$key}, @_); $$shr = $new } } else { my $val = shift; print " Value = '$val'\n"; my $valref = ref $val; if ($valref eq 'ARRAY') { my $new = &share([]); @$new = @$val; $$shr = $new } elsif ($valref eq 'HASH') { my $new = &share({}); %$new = %$val; $$shr = $new } else { $$shr = $val; } print "\n"; } }