Spidy has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, fellow Monks,

I have a piece of code that I'm writing. In order to make things easier, I've decided to store all of the configurable arguments into a hash, which is then stored on the hard drive, and loaded into the script(s) at runtime. The code which I used to recall the has is:

my %config = do "martha.225" or die("can't recreate config file: $! $@");
With "martha.225" being the configuration file. The problem is though, I have to put those 2 lines at the top of every script involving these variables that I write. This isn't an issue just yet, but soon enough there will be 25+ scripts relying on this information. Does anyone know of a way that I could use my config file, and not have to edit 25 files every time that I change the config file's name, or something?

Thanks,
Spidy

Replies are listed 'Best First'.
Re: Configuration, without a Module?
by ikegami (Patriarch) on Mar 20, 2006 at 23:17 UTC

    Your 25 scripts:

    my %config = do "config.pl" or die("can't recreate config file: $! $@");

    config.pl:

    do "martha.225" or die("can't recreate config file: $! $@");
    — OR —

    Your 25 scripts:

    use AppConfig;

    AppConfig.pm:

    package AppConfig; our @ISA = 'Exporter'; use Exporter; our @EXPORT = '%config'; our %config = do "martha.225" or die("can't recreate config file: $! $@"); 1;

    Update: $reply_text =~ s/@EXPORT_OK/@EXPORT/g;

      Decided to use your first method, it looks like it will work perfectly. Thanks!

      Spidy
Re: Configuration, without a Module?
by diotalevi (Canon) on Mar 20, 2006 at 23:17 UTC

    Put "-Mmartha225" into the environment variable PERL5OPT, rename your file to martha255.pm, and then put it someplace accessible.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊