in reply to Unitialized value warnings with require

Would really have to see your code to give you an educated answer. I wrote a module to pull in the variables from the flat file and send the data back to the calling prog as a hash reference.

The format on the variable file is 'variable:value':
store_dir:/path-to/the-storage-dir
Split on ':', create a hash. Send it back to the calling prog as a reference.

Here's some quick sample code from the calling prog:
my $config = getConfigVars (); my $storageDir = $config->{store_dir};
This is nice if you have a lot of programs that need to know what the store_dir is. You only have to modify your config file and all progs will recognize the change.

Alternatively if there are no other programs that care what store_dir is, why not store the vars in __DATA__ and have a routine that loops through those recs:
my %config; while (<DATA>) { my ($var, $val) = split (/:/, $_); $config{$var} = $val; } __DATA__ store_dir:/path-to/the-store-dir

Replies are listed 'Best First'.
Re: Re: Using Variables
by jryan (Vicar) on Dec 28, 2001 at 00:03 UTC

    Storable is a more reliable way to store variables. From the Storable manpage:

    use Storable; store \%table, 'file'; $hashref = retrieve('file');

    or alternatively:

    use Storable qw(nstore store_fd nstore_fd freeze thaw dclone); # Storing to and retrieving from an already opened file store_fd \@array, \*STDOUT; nstore_fd \%table, \*STDOUT; $aryref = fd_retrieve(\*SOCKET); $hashref = fd_retrieve(\*SOCKET);

    Of course, if you need to include other things besides variables in the config, you may want to consider turning your code into a module

      Storable is a more reliable way to store variables.

      Except that then you lose the ability to easily view and edit the file, which is what you'd like to be able to do with most config files (I like Storable, but not for this) :-)

        Using Data::Dumper instead of Storable, you get output that is both reliable and editable. It works for Net::Config...

            -- Chip Salzenberg, Free-Floating Agent of Chaos