in reply to Working with a legable config file
Whenever I need my program to read and save settings to a file, I like to use XML::Simple. Basically, you can dump a hashref / array ref or any combination thereof into a file. Then, you can read it back into an array / hash as well. Plus, with all the XML modules / packages out there (and for languages other then Perl) it becomes very easy to interface with your config files.
For instance, by using the XML out function, you could change:
my $data = { things => [ { foo => 'bar' }, { foo => 'baz' }, { foo => 'bam' }, ] };
Into XML like:
<things> <foo>bar</foo> <foo>baz</foo> <foo>bam</foo> </things>
And then after calling the function to read XML you can access it right from the hash ref! And, again, I can't stop stressing to you how portable XML is. If, in the future, you want to do something with that data, expand the project, or create a new program to work with the data, it's very simple to do. Of course, using a Perl module for another type of config file will do this for you, but it won't be portable across platforms. (I wish everything were coded in perl, but let's be realistic. Sometimes you need to work with Java/C/ASP/Whatever)
|
|---|