AriSoft has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am trying to use a directory structure as a database to present the data in the most accessible way. A file folder works like a hash with keys in flenames and data in files.

I found modules Tie::TextDir, DirDB and Tie::FileSystem which does something like what I am looking for. Would you recommend me some more sophistiated modules or ways to solve my problem?

I would prefer to have same interface which is used with shared variables in threads::shared. Including the option to insert nested hashes to hashes as nested directory stuctures.

Replies are listed 'Best First'.
Re: Database in a folder?
by cdarke (Prior) on Feb 16, 2010 at 11:46 UTC
    Would you recommend me some more sophistiated modules or ways to solve my problem?

    I can't see what your problem is, you have only described the solution. Using a directory as a high level index is a common enough solution, and if the modules you mention resolve the data in the way you wish then why go for anything more complex? Keep it simple.

    On the other hand, if there is some feature you need that these modules do not supply then ask away. Right now it is hard to see what you need that you do not have.

      Hi,

      My problem is to find the right tie::module.

      The data is currently a shared hash of shared hashes. I would like to save it into files where first hash key is filename and second hash key+data is serialized to a file. It is like a cardfile.

      I was hoping that there is some universal "tie to files" module but didn't find one which does this all without extra programming.

        Are you seeking to persist your data between runs of your program? Or offload the data to disk becuase of volume and memory constraints?

        If the former, it should be relatively trivial and safe. If the latter, with threads involved, it requires considerable thought and care. You might look at DBM::Deep, though there doesn't appear to be any mention of thread-safety one way or the other. It can certainly handle the hashes of hashes aspect, and has ACID transactions which might mean it would work from multiple threads.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Database in a folder?
by planetscape (Chancellor) on Feb 17, 2010 at 05:01 UTC
Re: Database in a folder?
by CountZero (Bishop) on Feb 16, 2010 at 20:03 UTC
    I would be careful with using threads on your database: depending on the filesystem you are using you can have nasty issues with concurrent access to the same file: what will happen if two threads try to change the same file? At best you get an error or at worst you mess up the contents of the file.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James