anyway the logic must be done by you: you can for example intercept CTRL-C and call a sub to store all the variables you need, then you need to modify the program to load the files that contains such stuffs on demand.
Remember that Storable can store only one variable so if you need more than one you need to do something like:
my ($fruit, $none, $arr, $drink) = @{retrieve('store-test.sto')}; (credit to kcott)
Consider this example that just retrieve vars from file:
use Storable qw(nstore retrieve);
# these are the vars replaced by load_from_file
my %conf = (a=>'A',b=>'B');
my %help = (a=>'letter A',b=>'letter B');
load_from_file('/path/to/file.sto');
sub load_from_file {
my $file = shift;
unless (defined $file){ return ; }
my $pfile = File::Spec->catfile($drive,$directories,'conf',$file);
if (defined $file && -e $pfile) {
my $mconf;
my $mhelp;
eval {($mconf, $mhelp )= @{retrieve ($pfile)}} ;
if ($@){ warn "WARNING no configuration in '$file'!\n"; return
+;}
else {
%conf = %{$mconf};
%help = %{$mhelp};
print "OK $file profile loaded.\n";
return 1;
}
}
else {warn "WARNING profile $file not found!\n";return}
}
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
|