Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Is this DBM::Deep behavior, or something with tie/bless? (normal)

by tye (Sage)
on Jan 30, 2008 at 04:35 UTC ( [id://665060]=note: print w/replies, xml ) Need Help??


in reply to Is this DBM::Deep behavior, or something with tie/bless?

Assigning to a tied array puts stuff in the database. It doesn't replace the array with an untied array. That is normal. The new array isn't tied so, of course, assigning to it doesn't cause a tie relationship to suddenly appear.

- tye        

  • Comment on Re: Is this DBM::Deep behavior, or something with tie/bless? (normal)

Replies are listed 'Best First'.
Re^2: Is this DBM::Deep behavior, or something with tie/bless? (normal)
by romandas (Pilgrim) on Jan 30, 2008 at 20:01 UTC
    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?
      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:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://665060]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2024-04-18 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found