Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Storable

by Tyke (Pilgrim)
on Feb 23, 2001 at 16:52 UTC ( #60474=note: print w/replies, xml ) Need Help??


in reply to Storable

A trick that I've found useful in TK apps is the following:
use vars qw/$CONFIG $DATA/;

BEGIN {
  $CONFIG = "$0.conf";
  $DATA = retrieve($CONFIG) if -e $CONFIG;
}
END {
  store($DATA, $CONFIG);
}
$DATA is a reference to a hash that contains the user entered data. This little addition to the program means the data entered by the user in the last session becomes the default in this session... saves a heck of a lot of typing - particularly during testing!

Replies are listed 'Best First'.
Re: Re: Storable
by TheoPetersen (Priest) on Feb 23, 2001 at 19:10 UTC
    An excellent technique which will find its way to my code very soon :)

    My variation was to have a human-readable config file, but keep the actual data in a hash written out by Storable. At startup the program checked the dates of the two files and re-parsed the config file if needed. I hadn't thought of using it to maintain user state though, nice job.

      ...or do both in one shot with Data::Dumper. Doing this prevented me from having to define a human-readable configuration-file syntax. Though I do process the Data::Dumper output slightly.

              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://60474]
help
Chatterbox?
[GotToBTru]: 99% of all deaths take place within 24 hours of ingesting di-hydrogen monoxide
[GotToBTru]: time for some C8H10N4O2 for me
[ambrus]: GotToBTru: wait, you tell only the atom totals of what you want? Is that like ordering food in a restaurant by telling only the nutrient amounts you need, or
[ambrus]: like when a medieval scientist supposedly proves his priority inventing something by having previously published an anagram of a thousand letters long summary of the invention?

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2016-12-06 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (104 votes). Check out past polls.