Re: Passing a single hash to a sub




sub test {
my ($k,$v,$ref) = @_;

# this makes a hash %h which is a copy of the hash in $ref
# also, it is local to this sub (not your intention)
#my (%h) = %$ref;
#$h{$k} = $v;

# instead, modify the hash in $ref
$ref->{$k} = $v
}
.



Relevant Pages

  • Re: Passing a single hash to a sub
    ... you're making copies of the hash. ... You want to directly modify the existing hash. ... modify the hash that $ref references: ...
    (comp.lang.perl.misc)
  • Re: Empty hash key produces funky results
    ... I was assigning parameter values to a hash like so: ... This way at least a "" value was being inserted into the hash. ... > return $str; ...
    (comp.lang.perl.misc)
  • assign STDIN to a hash ref
    ... I'm trying to assign STDIN to a hash ref... ... control if I don't learn to use references. ... User selects vendor and then selects the type of image (regular or ...
    (perl.beginners)
  • Re: how to create a hash whose key is a reference
    ... as the key but in the second one I want the reference to that string ... Hash keys are always strings. ... perfectly possible to take the reference of a key. ... al lthe work of keep the 2nd ref up to date - perhaps usinga Tie module ...
    (comp.lang.perl.misc)
  • Re: Problems passing a reference to a hash between functions
    ... PL> Uri Guttman wrote: ... >> yes that does a full shallow copy of the hashed row each time. ... still needs only a simple hash ref to be passed in and with no special ...
    (comp.lang.perl.misc)