dsalada has asked for the wisdom of the Perl Monks concerning the following question:
Basically what is going on here is that I have an array of hashes that I want to manipulate without mutilating the orginal. The reference to the array is a value of one hash and I wanted to have a reference to the changed array be the value of another hash. (Maybe that's just a long way of saying that I wanted to make a copy of an array from one hash into a another hash.) Anyway, once I have a reference to the anonymous array, everything works as expected except the third line. Instead of deleting a key/value from the second hash (%subs), it deletes the key/value from the original hash (%session). I don't understand. If it was a problem with my dereferencing and referencing, I would expect pop to pop from the original hash but it doesn't. I used Data::Dumper to spew the structure of $session{hierarchy_path} both before and after this little snippet just to make sure I wasn't that crazy! Here's what it showed me:my %subs = ( path => [ @{$session{hierarchy_path}} ] ); $subs{bottom_path_term} = ${pop(@{$subs{path}})}{term}; if (@{$subs{path}}) { delete $subs{path}[$#{$subs{path}}]{id}; } else { delete $subs{path}; }
Can anyone explain to me what's going on? BTW, I'm using Perl 5.6.1 on LinuxBefore: 'hierarchy_path' => [ { 'id' => 0, 'term' => 'Top of Hierarchy' }, { 'id' => '57000', 'term' => 'Education' } ], After: 'hierarchy_path' => [ { 'term' => 'Top of Hierarchy' }, { 'id' => '57000', 'term' => 'Education' } ],
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: weirdness with delete
by merlyn (Sage) on Jun 26, 2002 at 18:18 UTC | |
by dsalada (Scribe) on Jun 26, 2002 at 20:19 UTC | |
|
Re: weirdness with delete
by flounder99 (Friar) on Jun 26, 2002 at 19:49 UTC | |
|
Re: weirdness with delete
by Aristotle (Chancellor) on Jun 26, 2002 at 18:51 UTC |