Script::State - Keep script local variables
#!perl use Script::State; script_state my $count = 0; # set to last value if exists say $count++; # automatically write $count's current value to external file # to be read at next script execution
Keep this variable's state after script execution.
Explicitly store current state. This is called in END block.
Script::State stores local variables to file after script execution. Values of scalar variables with script_state are stored in another file, and the values are automatically loaded when script is executed at next time.
script_state
Script::State stores variable states to file at same directory of script ($0). For example, if $0 eq 'foo/bar.pl', filename containing state is 'foo/.bar.pl.pl'.
When Script::State is import()ed, it will load previous state from the state file, and at the time script_state() is called, bind corresponding value to the variable.
When Script::State's END block is entered, this stores current variable values to the state file.
This modules currently uses Data::Dumper::Dump and eval() to store/load state, maybe unsafe.
This modules currently does not lock state files.
motemen <motemen {at} gmail.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Script::State, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Script::State
CPAN shell
perl -MCPAN -e shell install Script::State
For more information on module installation, please visit the detailed CPAN module installation guide.