Slaven Rezić > savevars > savevars

Download:
savevars-0.07.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.07   Source  

NAME ^

savevars - Perl pragma to auto-load and save global variables

SYNOPSIS ^

    use savevars qw($frob @mung %seen);

DESCRIPTION ^

This module will, like use vars, predeclare the variables in the list. In addition, the listed variables are retrieved from a per-script configuration file and the values are stored on program end. The filename of the configuration file is "$ENV{HOME}/.${progname}rc", where progname is the name of the current script.

The values are stored using the Data::Dumper module, which is already installed with perl5.005 and better.

FUNCTIONS ^

cfgfile

Return the pathname of the current configuration file.

writecfg

Write the variables to the configuration file. This method is called at END.

dont_write_cfgfile

If this function is called, then the configuration file will not be written at END.

NOTES ^

If you want to be nice to your users and do not want to require them to install this module, you can use this snippet of code to use the savevars or the vars module, whatever is available:

    BEGIN {
        my @vars = qw($var1 $var2 @var3 %var4);
        eval           q{ use savevars @vars };
        if ($@) { eval q{ use vars     @vars } }
    }

Just put all the variables to be saved into the @vars array.

CAVEATS ^

cfgfile() uses the $< variable to determine the current home directory. This might not be what you want if using setuid scripts.

BUGS ^

Because getpwuid() is used, this module will not work very well on Windows. Configuration files will be stored in the current drive root directory or, if the $HOME environment variable exists, in the $HOME directory.

AUTHOR ^

Slaven Rezic <eserte@cs.tu-berlin.de>

Copyright (c) 1998-2001 Slaven Rezic. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO ^

vars.

syntax highlighting: