11.7.05

Config::General

Couple of problems this week. First was find a simple method of storing and accessing a home grown configureation file in the style Description Tab Value.
There are probably a 1000 different ways of getting at the contents of a such a file.

This is an example, a simple text file and while I could write a small program to parse and feed the Description=>Values into a hash, thought I would try Config::General Turns out to be an OK program.


horse grey
banana yellow
cow brown
cow blue
MainPhone 4556666
FaxPhone 3337777
SecretaryFullName "Helen Smith"
SecretaryName Helen
MembershipFees $40.00pa

and this little program results in the output below

-------------------Program-------------------------

#!/usr/bin/perl

use strict;
use Config::General;
my %config = ParseConfig("rcfile");

while ( my ( $key, $value ) =
each(%config) ) {

if ( ref($value) eq "ARRAY" ) { print
"$key\t@{$value}\n" }
else {
print "$key\t$value\n";
}
}

__END__

--------------------Output--------------------------

banana yellow
cow brown blue
SecretaryName Helen
SecretaryFullName Helen Smith
MainPhone 4556666
FaxPhone 3337777
MembershipFees $40.00pa
horse grey

----------------------End--------------------------

I don't recommend anyone include monetary charges in easily amended configuration files. Too easy to change!

No comments: