in reply to unexpected behavior on hash passed by reference
$ref = {}; # why won't this replace the underlying hash?
$ref is a scalar that holds a reference to a hash. {} creates a new anonymous hash, and you're overwriting the hashref with a reference to the new anonymous hash. In other words, you're just changing which hash $ref points to. To clear the hash pointed to by the reference, you need to dereference it: %$ref = (); will clear the hash pointed to by $ref (without removing the blessing).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: unexpected behavior on hash passed by reference
by perlfan (Parson) on Feb 26, 2022 at 18:47 UTC | |
by haukex (Archbishop) on Feb 26, 2022 at 18:56 UTC | |
by LanX (Saint) on Feb 27, 2022 at 00:15 UTC |