in reply to Fast Recall
I can't use a db to do thisYes of course you can!
Perl has this wonderful built-in database system, called ... hashes.
And you can persist the datastore by binding your hash to a file with dbmopen.
The beauty of this is that it is totally transparent. Once you bind the hash to the database with dbmopen you keep using the hash as usual but Perl takes care of storing and fetching the data to/from storage.use strict; use warnings; use 5.012; # Add some data to the datastore my %failed_jobs; dbmopen %failed_jobs, './failed_jobs', 0666; $failed_jobs{'job_1234'} = 1; dbmclose %failed_jobs; # Now see if the data persisted my %check_failures; dbmopen %check_failures, './failed_jobs', 0666; for my $job (keys %check_failures) { say "$job = $check_failures{$job}"; } dbmclose %failed_jobs;
For a more sophisticated version of this mechanism, check out the tie function.
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
|
|---|