Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2021-11-27 11:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found