Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

My preferred way of handling config data in Perl is:

by rinceWind (Monsignor)
on Dec 14, 2006 at 00:42 UTC ( [id://589705]=poll: print w/replies, xml ) Need Help??

Vote on this poll

.ini files
[bar] 82/26%
perl code (eval, do or require)
[bar] 84/26%
shell environment variables
[bar] 18/6%
YAML
[bar] 46/14%
JSON
[bar] 3/1%
XML
[bar] 44/14%
xSV (huh?)
[bar] 4/1%
Something else: please tell
[bar] 38/12%
319 total votes
Replies are listed 'Best First'.
Re: My preferred way of handling config data in Perl is:
by tbone1 (Monsignor) on Dec 14, 2006 at 12:34 UTC
    .ini files.

    Encrypted .ini files.

    In Sumerian.

    (Although once, because of a typo, I created a .nin file and the code got all depressed, dressed in black, bemoaned having to sell out to the music industry, and moved to the local art district. Who knew?)

    --
    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee

      Actually, I think I saw it in Cleveland once :-)
      .ini files. Encrypted .ini files. In Sumerian.
      Also known as nam-shubs.

      =cut
      --Brent Dax
      There is no sig.

      I'm older; I'd expect a nin file would cause the code to write pornographyerotica, and date your spouse||parents||significant other||children, probably all at once.

      emc

      At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.

      —Igor Sikorsky, reported in AOPA Pilot magazine February 2003.
Re: My preferred way of handling config data in Perl is:
by zshzn (Hermit) on Dec 14, 2006 at 04:00 UTC
    Whatever happened to .txt and .config files?
      I usually use .txt files instead of .ini. Alternatively, .rc files are nice as well... On the other hand, if you will be passing your script to someone else, embedding the config data in the script is a little more portable (although forces you to update the code eveytime there is a config change, versus just messing with the .ini/ .txt/ .rc file).

      Ah, TIMTOWTDI.

      tubaandy
Re: My preferred way of handling config data in Perl is:
by mce (Curate) on Dec 14, 2006 at 10:06 UTC
    My All time favorite Config::Simple. Plain old ini files.

    ---------------------------
    Dr. Mark Ceulemans
    Product Manager
    Bull, Belgium
Re: My preferred way of handling config data in Perl is:
by rhesa (Vicar) on Dec 14, 2006 at 00:56 UTC
Re: My preferred way of handling config data in Perl is:
by ikegami (Patriarch) on Dec 14, 2006 at 04:09 UTC
    Command line args
Re: My preferred way of handling config data in Perl is:
by gloryhack (Deacon) on Dec 14, 2006 at 12:37 UTC
    I prefer YAML, but the folks who pay me prefer .ini files. The folks who pay me think a closure is what keeps a brassiere from falling off...
Re: My preferred way of handling config data in Perl is:
by Nkuvu (Priest) on Dec 14, 2006 at 17:41 UTC

    I ask the user. Every single time.

    Sure, it's repetitive, and yes, the users get frustrated, but it's so fun to ask them the same questions every time (with confirmation for each question). The best part is when I ask for configuration options that my scripts don't use. ("Enter the distance from the Earth to the sun, in centimeters: ")

    Or maybe I just use text files -- but that's a less interesting answer, so...

Re: My preferred way of handling config data in Perl is:
by strat (Canon) on Dec 15, 2006 at 10:05 UTC

    It depends on what kind of data is in the configuration

    I usually use a Module called SomeNamespace::Config.pm which either contains the configuration or provides an interface for it, or uses "Plugins" like SomeNamespace::Config::AccessData.

    • For synchronizing data for metadirectories, I often save the configuration of the connected directories in the central data directory and access it through Net::LDAP or DBI and write a little application to change it. And if you want to work with a version control system, you can easily put LDIF- or SQL-files under version control. This is very easy because if you have several systems (e.g. develop, test, integration, preproduction, production), you don't need to edit config files or perl code manually. The only problem is the data you need to access the central data directory: I either put them into a perl module like Namespace::Config::AccessData or the like, or put it into a little INI or YAML file.
    • For web or Tk applications I like both YAML or ini files, or if it get's too complicated: even a perl module.
    • For little command line scripts, Getopt::Long and friends are often absolutely ok

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Re: My preferred way of handling config data in Perl is:
by jonadab (Parson) on Dec 14, 2006 at 11:18 UTC
    require './config.pl';

    After all, sometimes the configuration needs to calculate values or define objects or subroutines (e.g., a callback). An .ini file just can't handle those needs. And sometimes defining a set of related options together, e.g. with map, improves the clarity of the config file, and .ini can't do that, either.


    Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.
Re: My preferred way of handling config data in Perl is:
by EvanK (Chaplain) on Dec 14, 2006 at 20:53 UTC
    For small projects, Config::Simple, and for larger ones, Config::General

    __________
    Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
    - Terry Pratchett

Re: My preferred way of handling config data in Perl is:
by talexb (Chancellor) on Dec 14, 2006 at 03:25 UTC

    YAML rocks my world .. but watch out for the indentation .. muck it up and data will mysteriously disappear. Thanks Ingy!

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      yaml is neat, but the std module seems quite slow reading/writing?
        Use YAML::Syck then.

        use Best [[ qw/ YAML::Syck YAML / ], [qw/Load Dump/]; print Dump($complex_thingie);

        Not only slow but buggy as well.

Re: My preferred way of handling config data in Perl is:
by eserte (Deacon) on Dec 14, 2006 at 07:33 UTC
    I started using YAML again, since there is another YAML handling module (YAML::Syck) and INGY restarted YAML.pm development. For emacs users, there is yaml-mode and now it's also possible to use schemas on YAML (or JSON) files: Kwalify
Re: My preferred way of handling config data in Perl is:
by stonecolddevin (Parson) on Dec 16, 2006 at 08:29 UTC
Re: My preferred way of handling config data in Perl is:
by philcrow (Priest) on Dec 14, 2006 at 13:54 UTC
    We use Gantry::Conf more and more. All conf files go in /etc/gantry.d. They are instance tagged, so all an app or script needs to know is the instance name. Pass that to the retrieve method and presto all your conf in a lovely hash. It even handles location specific conf to mimic PerlSetVars from Apache conf. The instances can easily share common conf in several ways. The conf file format is up to you, but we use Config::General's format.

    Phil

Re: My preferred way of handling config data in Perl is:
by leocharre (Priest) on Dec 14, 2006 at 06:40 UTC

    CGI::Ex::Conf is a nice interface to various conf type files. You can use YAML (yeah!), ini, json, etc files.

Re: My preferred way of handling config data in Perl is:
by Ben Win Lue (Friar) on Dec 14, 2006 at 09:25 UTC
    something else:

    Most time I do my konfiguration in the database, especially complex konfiguration.

    If I don't have a database or I have to configure which database to use, I do configuration by ini-files or environment variables.

      And where do you store the information about connecting to the database?

      @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;
        ++ just for your .sig.

        Jack

        In same place you store the information that says how to read from the environment / the command line / a config file / etc. ?

        At some point, you have to tell the program where to look, and what to look for, no matter what it is you're looking at...

Re: My preferred way of handling config data in Perl is:
by Juerd (Abbot) on Dec 15, 2006 at 00:46 UTC
Re: My preferred way of handling config data in Perl is:
by Discipulus (Canon) on Dec 15, 2006 at 08:00 UTC
    ok small config go into my %conf; at the very beginning.

    medium config below wonderful __DATA__ token (no one mentioned it. I' m so stupid to do so ?!?).

    big configs shared between 2 or more scripts go into a quick 'n dirty exported on request only  %conf_one in a conf_Project.pm

    ty all

    Lorenzo*
Re: My preferred way of handling config data in Perl is:
by arc_of_descent (Hermit) on Dec 15, 2006 at 08:25 UTC

    Text files, with simple one-liners, enclosed in xml tags if there are multiple sections. All thanks to Config::General


    --
    Rohan

Re: My preferred way of handling config data in Perl is:
by nimdokk (Vicar) on Dec 14, 2006 at 17:00 UTC
    Sorta like .ini I suppose, but I simply use files named .cfg instead (depending on what it is being used for of course :-)
      Well, I name them .conf actually :)
Re: My preferred way of handling config data in Perl is:
by hiseldl (Priest) on Dec 14, 2006 at 21:33 UTC
    Config::General because I like the variable substitution, the grouping/sub-grouping capability, and it handles Apache-style and ini files as well. Plus, it has a tie interface.

    --
    hiseldl
    What time is it? It's Camel Time!

Re: My preferred way of handling config data in Perl is:
by Mutant (Priest) on Dec 14, 2006 at 11:48 UTC
    "YAML" is catchy and fun to say. Try it. "YAML, YAML, YAML!!!"
Re: My preferred way of handling config data in Perl is:
by gam3 (Curate) on Dec 14, 2006 at 22:42 UTC
    ! XML
    -- gam3
    A picture is worth a thousand words, but takes 200K.
Re: My preferred way of handling config data in Perl is:
by SFLEX (Chaplain) on Dec 14, 2006 at 12:26 UTC
    "Something else: please tell"

    Ok, its MySQL.
Re: My preferred way of handling config data in Perl is:
by mr_mischief (Monsignor) on Dec 14, 2006 at 21:46 UTC
    I've been use'ing Perl modules for configuration a bit lately. It's almost like hard-coding, but it's in a different file and I make a hash for each feature group that is kind of self-documenting.

    It might not be the most user-friendly, but I tend to use these for things like configuring database names and hostnames, then stick user-level configs behind an options interface within the user interface.


    Christopher E. Stith
Re: My preferred way of handling config data in Perl is:
by ides (Deacon) on Dec 21, 2006 at 15:02 UTC

    Gantry::Conf is all I use these days. However, Config::General is another good choice IMHO.

    Frank Wiles <frank@revsys.com>
    www.revsys.com

Re: My preferred way of handling config data in Perl is:
by parv (Parson) on Dec 17, 2006 at 21:51 UTC
    Programs that I advertise about (and/or not in public domain) use command line arguments, and sometimes __DATA__, for the configuration. Otherwise, plain old variables & possibly __DATA__ hold the configuration.
Re: My preferred way of handling config data in Perl is:
by alpha (Scribe) on Dec 17, 2006 at 22:01 UTC
    Data::Dumper + perl code ftw ;)
Re: My preferred way of handling config data in Perl is:
by spatterson (Pilgrim) on Dec 18, 2006 at 17:35 UTC

    Oh, so many options *grin* Appconfig::File or XML::Simple for persistent configuration. AppConfig::File's easy to edit manually, XML::Simple is handy if you want perl to edit its own config file.

    Plus my vars for quick & dirty hacks & command line parameters sometimes as well.


    just another cpan module author
Re: My preferred way of handling config data in Perl is:
by pajout (Curate) on Dec 20, 2006 at 14:32 UTC
    I prefer this way, upper has higher priority:
    • command line arguments
    • %ENV
    • file configuration (it means XML for me)
    • hardcoded defaults
    Mixing these options gives me desired flexibility.

    The other practice, which I use sometimes, is to treat relative paths as relative to real location of the executed file (excluding mod_perl cases).

      The other practice

      No way that I am prepared to discuss my "other practice" on a public forum :-)

      Cheers,
      Rob
Re: My preferred way of handling config data in Perl is:
by sir_lichtkind (Friar) on Dec 24, 2006 at 12:20 UTC
    I like Config General, but just as HoH. It sucks while serialisation of Arrays, so in this case i prefer YAML, waiting on YAML::Tiny
Re: My preferred way of handling config data in Perl is:
by starX (Chaplain) on Dec 18, 2006 at 21:17 UTC
    other: unix hidden files (.filename) that contain init data. Anything complex I would prefer XML though.
Re: My preferred way of handling config data in Perl is:
by parv (Parson) on Mar 19, 2008 at 06:30 UTC

    I had mistakenly expected Config::(Simple|Tiny) to support reading from a given file handle based on their name. Config::Ini had the same problem of expecting only a file name, not a file handle. As a result of that, I use Config::General instead.

Re: My preferred way of handling config data in Perl is:
by temporal (Pilgrim) on Oct 18, 2012 at 14:42 UTC

    I'm a fan of using AppConfig

    Handling CLI and config file options in the same module - quite handy.

Re: My preferred way of handling config data in Perl is:
by Tux (Canon) on Jan 02, 2007 at 14:27 UTC

    I was to say "who needs configure stuff, hard-code it all, so people cannot make mistakes", but then I realized that .ini files should of course be .rc files (what's in a name).

    Then there are <DATA> (__END__), command-line-arg driven hash keys that make you select a prefefined configuration by key, etc. etc.

Re: My preferred way of handling config data in Perl is:
by lovekumar (Initiate) on Dec 20, 2006 at 09:46 UTC
    I would make a .pm file let say Config.pm, store my config in form of Data Structure let say $CONFIG and export this var to other modules. require Exporter; use vars qw/ @EXPORT/; @EXPORT = qw/$CONFIG/; do something with $CONFIG now.
Re: My preferred way of handling config data in Perl is:
by Anonymous Monk on Dec 19, 2006 at 18:12 UTC
    what better than the registry?

      But Linux doesn't have a registry!

View List Of Past Polls


Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-03-19 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found