in reply to Re^4: Help !!! Symbolic Math Factroize Subroutine is clobbering my hash
in thread Help !!! Symbolic Math Factroize Subroutine is clobbering my hash
The array needs to be reset. This is because subsequently the array needs to be populated with other items; the next hash will be an array of these other items. It the array is not reset, items from the previous operation will be appended to the items in the current operation....
No. It doesn't. Use a different array.
You've stored a reference to @this_array in the hash; if you modify it, then you are modifying (deleting) the data that reference points to.
You might just as well not have stored it in the first place, if as soon as you do, you destroy the data the reference points to.
Update:Maybe this will clarify things?:
@this_array = 0..9;; $hash{ akey } = \@this_array;; pp \%hash;; { akey => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] } @this_array = ();; pp \%hash;; { akey => [] }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Help !!! Symbolic Math Factroize Subroutine is clobbering my hash
by ipreferperl (Novice) on Dec 26, 2014 at 04:00 UTC |