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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Module: Config::IniFiles

Author: Scott Hutton, currently maintained by Rich Bowen

Where is it?

Config::IniFiles is a module intended to make life easier for those who rely on flat configuration files. Specifically, files that use the "Windows style" format.

Config::IniFiles offers an easy and reliable method of reading and writing configuration files that utilize the Section key=value format. You can place the entire contents into a multil-dimensional hash, keyed on section, and/or easily pull those sections in their own hash.

I tried this module out as an alternative to what were/are multiple methods of "configuration" being used by my currrent client. Currently, my client's Perl CGI/batch scripts utilize a combination of database, hard-coding and tab-delimited flat files for setting default/site-specific configurations within the applications. Method used seems to depend on the author/maintainer of the day.

My intent was to implement the practice of a single standard method for storing configuration information. Although we develop and run on HP-UX, the development team that is responsible for maintenance and development are more comfortable with Windows and are all familiar with the "Windows style" configuration file format. I am referring to this style as "windows style", if a monk can identify this format properly, I will gladly update my use of this designation!

The style of configuration file is as follows:

[Section1] key1=value1 key2=value2 [Section2] key1=value1 key2=value2

I am sure you've been exposed to this formatting. If not, it is pretty self-explanatory.

My goal was to create a file similar to the following which would isolate common variables associated with the "current" environment that the Perl was executing in. In this case, dev/test/prod. The single configuration file would look similar to this (simplified for this example):

[prod] ORACLE_HOME=/path/to/oracle/prod ORACLE_SID=prod_sid [test] ORACLE_HOME=/path/to/oracle/test ORACLE_SID=test_sid [dev] ORACLE_HOME=/path/to/oracle/dev ORACLE_SID=dev_sid

The code itself determines which environment it is in based on the hostname

so lets proceed to using Config::IniFiles

# Make the module available use Config::IniFiles; # now nab the entire config file contents into the %ini hash my $ConfigFile = "/path/to/inifile/inifile"; tie my %ini, 'Config::IniFiles', (-file => $ConfigFile); # now grab the relevent section into it's own hash, we're assuming th +at it's "prod" for this example my %Config = %{$ini{"prod"}}; # now we have access to our keys in the hash print "Oracle home is $Config{ORACLE_HOME}"; print "Oracle SID is $Config{ORACLE_SID}";

While I haven't used all the features of this neat tool, here are a few features that would be real useful if we in fact utilize such a method.

- val ($section, $parameter) - Returns the value of the specified +parameter in section $section. - setval ($section, $parameter, $value, [ $value2, ... ]) - Sets t +he value of parameter $parameter in section $section to $value (or t +o a set of values). - newval($setion, $parameter, $value [, $value2, ...]) - Adds a new v +alue to the configuration file. - delval($section, $parameter) - Deletes the specified value from th +e configuration file - Sections - Returns an array containing section names in the configu +ration file. If the *nocase* option was turned on when the config object + was created, the section names will be returned in lowercase.

While I have yet to receive authorization to make such changes to my client's applications, I have a good tool for making it happen.

That is all for now...

Note: Updated typo 8/12/02 per demerphq's head up

Note: Updated 9/30/02 - modify <cite> tags to italic since cite wasn't

In reply to Config::IniFiles by wardk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (5)
    As of 2020-05-27 02:12 GMT
    Find Nodes?
      Voting Booth?
      If programming languages were movie genres, Perl would be:

      Results (152 votes). Check out past polls.