Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Working with a legable config file

by Vautrin (Hermit)
on Apr 03, 2004 at 04:13 UTC ( #342227=note: print w/replies, xml ) Need Help??

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)

Want to support the EFF and FSF by buying cool stuff? Click here.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://342227]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2022-01-22 11:18 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (62 votes). Check out past polls.