in reply to Re: Re: How do you load configuration variables
in thread How do you load configuration variables

I always create a module to handle program configuration, and I always call it Program::RC

Why not just write that module once, name it once, and then reuse it in each application? Better yet, why not just use a module that already exists for just such a purpose; something like AppConfig, for instance?

No matter how you access your config file — AppConfig, a home-brewed module, do $config or die $!, whatever — it's still best to hardcode the path in your program and allow it to be overridden with command-line args or envariables as necessary.

"My two cents aren't worth a dime.";
  • Comment on Re: Re: Re: How do you load configuration variables

Replies are listed 'Best First'.
Re: Re: Re: Re: How do you load configuration variables
by Excalibor (Pilgrim) on Jul 14, 2003 at 10:11 UTC

    Hi there,

    It's a good question, and it deserves a good answer: I cannot always choose my config files format. So my Foo::RC will create an abstraction layer on top of the config file.

    Another goo reason is that this way I create the interfaces I like (which I would have anyway to write better code, eg.:

    my $rc = new Foo:RC; my $ldap = Net::LDAP->new( $rc->ldap_data ); $ldap->bind( $rc->ldap_bind_data ) or die $@;

    Among a wide amount of possible situations.

    Granted, Foo::RC would use AppConfig or any other of the configuration modules available in CPAN. But when you have to read INI files, normal /etc/* kind of config files (hence calling the module RC), XML config files or config data stored in a LDAP directory, Foo::RC makes a lot of sense and life much more easier...

    Best regards,

    our $Perl6 is Fantastic;