mvr707 has asked for the wisdom of the Perl Monks concerning the following question: (hashes)

I'm maintaining a directory as a perl hash. New employees get added and old get deleted as time passes by. What's the optimal way to maintain the hash such that I can recover the state of the hash at any given time?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: Revision controlled Perl DataStructure
by rob_au (Abbot) on Dec 27, 2001 at 06:19 UTC
    Your best method of implementing this would be to write the data structure to a dated text file using a serialisation/dumper module such as Storable or Data::Dumper - An example piece of code might look something like this:

    use Data::Dumper qw/Dumper/; use IO::File; use strict; my %hash = { # Your data structure lies within %hash }; my $fn = "dump." . sprintf("%04d%02d%02d", (localtime)[5] + 1900, (loc +altime)[4] + 1, (localtime)[3]); my $fd = IO::File->new($fn, "w"); if (defined $fd) { print $fd Dumper(\%hash); $fd->close; };

    Note that this code is very rough and should not be used in this form - A better revision would incorporate file locking, tests for file existence and better time stamping.

     

    perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Re: Revision controlled Perl DataStructure
by expertseries (Initiate) on Mar 08, 2006 at 16:02 UTC
    Here's another, rob thanks for that example of sprintf.
    print "Content-Type: text/plain;\n\n"; #------------------------------------------------------------------ # Current time as 'YYYYMMDD.HHMMSS' (GMT) ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime(time); $revision = sprintf("%04d%02d%02d.%02d%02d%02d", $year+1900,$mon+1,$mday,$hour,$min,$sec); #------------------------------------------------------------------ print "\n\nRevision: $revision\n\n";
Re: Revision controlled Perl DataStructure
by mvr707 (Initiate) on Dec 29, 2001 at 08:43 UTC
    But the idea of a general framework should be good audit tool on persistent datastructures.. Exactly like a revision control system like CVS allows me get a file as of any date/time...i am looking for similar feature for perl datastructure like hash which can be made persistent using Storable e.g.

    Originally posted as a Categorized Answer.

Re: Revision controlled Perl DataStructure
by mvr707 (Initiate) on Dec 28, 2001 at 03:06 UTC
    I am doing a similar stuff using Storable. But the strategy itself is not optimal... storing the FULL data for each snapshot. I was thinking of incremental storage and inheritance etc..

    Originally posted as a Categorized Answer.