Thanks for the help!
So, if I use 'untie @array' prior to the reassignment, that should work, right? Does assigning undef do the same thing?
On a not-strictly-Perl question, a friend who I had look at the same code said I was improperly reusing a variable by assigning a value back to it, but I'm not sure why he thought that was improper. Is there some part of 'programming best practice' that talks about variable reuse? | [reply] |
Is there a reason you want to untie the array? Generally, you just care about the data being on the disk and don't much care beyond that.
As for assigning the variable back to itself, it's generally frowned upon because it's usually a no-op. If it actually does something, then there's deep magic going on and, in general, deep magic is usually clever magic. Clever is the polite way of saying "stupid."
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] |
| [reply] |
The reason for 'untie'ing the array is related to my program using Data::Compare to compare data structures. The DBM::Deep database stores a hash of arrays (which have a hash as an element, etc). When my program runs, it retrieves the old info from the database to compare it with the new live information.
However, Data::Compare fails when comparing the two arrays (old and new info) because the old array is tied to the DBM, effectively comparing data structures that aren't alike (my logical/mental representation notwithstanding) since DBM::Deep hashes and arrays are objects, I think, as opposed to the regular hash/array structure of the new information in memory.
The two solutions I thought of (assigning the database array to a temp variable; assigning the new information to a temp spot in the database) both do not work (for differing values of 'do not work') due to the variables getting tied to the database.
I could potentially write a plugin for Data::Compare to handle this, but from what I can see that is way beyond my current ability.
I would post my code, but haven't finished writing it yet. :) The "variable reuse" problem (I believe) is just an artifact of my test code above; I don't think it'll exist in my actual code.
| [reply] |