Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Re: How do you load configuration variables

by sauoq (Abbot)
on Jul 14, 2003 at 06:17 UTC ( [id://273888]=note: print w/replies, xml ) Need Help??


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.

-sauoq
"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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://273888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found