Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Config file recommendations?

by Spidy (Chaplain)
on Mar 19, 2008 at 14:52 UTC ( #675013=note: print w/replies, xml ) Need Help??

in reply to Re: Config file recommendations?
in thread Config file recommendations?

That does seem to be what I'm looking for - if I had a config file like this:
%config = ( foo => bar, bat => baz, );
How would I use that inside my Perl script, and have it globally available? Would require config; automatically setup the %config hash for the script that required it?

Replies are listed 'Best First'.
Re^3: Config file recommendations?
by kyle (Abbot) on Mar 19, 2008 at 15:21 UTC

    I think maybe you're looking for Exporter. With it, you can have a module that will place a variable into the namespace of a program that uses it.

      This is what I've been trying, but it doesn't quite seem to work:

      use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(%config); %config = ( foo => bar, baz => bat );

      But I would still get the error Global symbol "%config" requires explicit package name. The code to use my config file was:

      use config;

        Main file:

        use strict; use warnings; use lib '.'; use MyConfig; use Data::Dumper; print Dumper \%config;

        package MyConfig; use strict; use warnings; use Exporter; our @ISA = qw(Exporter); our %config; our @EXPORT = qw(%config); %config = ( foo => 'bar', baz => 'bat', ); 1;

        And the output:

        $VAR1 = { 'baz' => 'bat', 'foo' => 'bar' };

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://675013]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2018-01-19 04:40 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (215 votes). Check out past polls.