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

I am writing a database app for my photo library (of about 2500 pics). I have been (so far) using a flat file to store the data. Every time the script is accessed, I load the database and build an array of hashes.

Then, when I save the data, I break everything back down into a character delimited text file.

While PerlMonks was out of commission, I broke down and bought a book (Perl Black Book). It mentioned the Storable module. I loaded it from CPAN. I cannot get it to work. I am running it on a Win2000 server. I am not certain if it is something I am doing wrong.

If I leave in the references to Autoloader, I get errors that it cannot locate autosplit.ix. If I remove the references to Autoloader(as other modules have instructed for Win environments), I get an error: Can't locate object for module Storable in @INC at line so-and-so in my script.

I am unfamiliar with this error and have run out of ideas. I am fairly new to Perl, so I imagine that this is a simple error on my part, but I'm flummoxed just the same.

Any ideas/suggestions would be GREATLY appreciated.

Replies are listed 'Best First'.
Re: Desperately needing help with Storable
by Anonymous Monk on Feb 09, 2002 at 00:00 UTC
    You have installed it by simply copying over the .pm file into your perl libraries directory. Thats not how it works. You need a C compiler, and a make tool (most likely nmake on Win32). If you're a beginner, it's probably a lot easier for you to type:
    C:\> ppm ppm> install Storable ... ppm> quit
    And it will install a pre-compiled binary for you. Matt.
      Thanks. I don't have a compiler or a make tool. I have not installed many modules - one or two - and have not had this problem before. I'll start looking.

        If you are using ActiveState Perl, use their PPM installer. ActiveState has precompiled binaries for most the common ones, hence you will not need a compiler to install.


        <cite>Just a tongue-tied, twisted, earth-bound misfit. -- Pink Floyd</cite>

Re: Desperately needing help with Storable
by YuckFoo (Abbot) on Feb 09, 2002 at 19:45 UTC
    A better solution might be to use a DBM, which is basically a hash that resides (persists) on disk instead of in memory. This is very useful for simple databases. For more complex data structures you can add MLDBM.

    Unfortunately the Little Black Book does not have a lot of discussion about this. I highly recommend the Perl Cookbook for 'How do I...' solutions.

    Maybe someone here can add some pointers to online resources about getting started with DBMs?

    YuckFoo

      As a matter of fact, I did consider going with the DBM solution. However, from what I have read in the Black Book, it did not seem to support an array of hashes. I will research the MLDBM, though. Thanks for the suggestion and for the book recommendation. What I am going for is a performance boost. What do you think would process faster - the Storable routines, or the database routines? I am beginning to think that it is all a wash since I have so many records. Thanks again.
        I think MLDBM uses the Storable routines. You might be able to squeeze some performance by using Storable directly?

        I think it will depend most on how you are using the data. If you are looking at every record in the database each time, I'm not sure any of these solutions will be faster than reading the text file like you are now.

        If you need access to a limited number of records at a time, DBM performance should eventually be better, given enough records.

        DBM is easy to try and good to know. Performance is hard (for me) to guess. So give it a shot, let me know how it goes!

        Regarding your list of hashs, provide a key and it becomes a hash of hashes.

        You access $pics{'MeAndDog'}->{date}. Now it's DBM-able. Use MLDBM if you have complex data to store, but keep in mind MLDBM and Storable are stringifying and unstringifying the data, not sure of the performance hit.

        If each picture simply has a list of attributes, you can combine the key and the attribute to make a new hash key and use a simple DBM. So you access $dbm{'MeAndDog.date'}, $dbm{'MeAndDog.size'}, $dbm{'MeAndDog.text'}, etc.

        HTH helps, had to rush the reply cause I'm outta here!

        YuckFoo, happy to have had the opportunity to use 'unstringifying'.