I have a subroutine, which gets a hashreference as a parameter.
I can manipulate single hashvalues by reference.
I want to replace the whole hash, which the reference point at, so that everywhere, where this hash was references the changes become visible.
sub replace{
my $hashref = shift;
# can manipulate hash here
$hashref->{key} = "newValue";
# how to replace replace the hash here by a new hash
$newHashRef = {
key => "value",
key2 => "value2",
};
}
Is that possible?
%$hashrefdenotes “the hash that$hashrefrefers to”, and assigning to that hash replaces its contents, just as it would if no reference was involved.