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

I have a program with adds values cumulatively to a hash contained within an object..

The only problem is that when the file that I use for input becomes very large, the amount of memory needed becomes very large too...

Is there any way to offload some of the structure onto hard disk in the form of a file ? I've looked at Storable, Data::Dumper and also writing out the data myself (calling a method named write_to_disk after x number of invocations).. can someone please tell me any advantages of using one method over another ?
thanks

Replies are listed 'Best First'.
(ar0n) Re: making object hashes persistent
by ar0n (Priest) on Apr 23, 2001 at 14:51 UTC
    If your datastructure is a simple key-value hash (i.e. not a hash containing arrayrefs, hashref, etc), you could tie your hash to a DBM file to write directly to the disk. This way your memory usage would be minimal.

    See arhuman's reply!

    ar0n ]

      For more complex structures (constaining refs)
      you can play with MLDBM
      It uses Data::Dumper by default to serialize your data,
      but you can use your favourite persistence module instead, like Storable for example...

      "Only Bad Coders Badly Code In Perl" (OBC2IP)
Re: making object hashes persistent
by gildir (Pilgrim) on Apr 23, 2001 at 17:17 UTC