From: Tim Musson [mailto:[EMAIL PROTECTED]]
> I like this option the best of the 3, but it is still hard to give to
> a non programing person and not expect them to mess up setting the
> vars...
> 
> ie, => is what you separate things with, explaining which ' to
> use (' not `), end each parameter line with a ,

You might like to check out XML::Simple it was designed for exactly
this problem.

Using Jos' example:

 JIB> ### config.pl ###
 JIB> $href = {
 JIB>     usr    => 'foo',
 JIB>     pwd  => 'bar',
 JIB>     host  => 'bleh.com',
 JIB> }; 

If you put your config data in a file called foo.xml:

  <config>
    <usr>foo</usr>
    <pwd>bar</pwd>
    <host>bleh.com</host>
  </config>

and your script was called foo.pl:

  use XML::Simple;

  my $config = XMLin();

  print "Host: $config->{host}\n";

Then you have a script which can be configured by someone
who doesn't know Perl.

The XMLin() function takes all sorts of optional arguments
telling it where to find the XML and how to treat it, but if
you don't supply any arguments it simply looks for a file called
<script name>.xml in the same directory as the script.

XMLin() returns a hashref.  Nested elements in the XML get
returned as nested hashrefs or arrayrefs.

More info at:

  http://web.co.nz/~grantm/cpan/

Regards
Grant



=====================================================================
Grant McLean       | email: [EMAIL PROTECTED] | Lvl 6, BP House
The Web Limited    | WWW:   www.web.co.nz    | 20 Customhouse Quay
Internet Solutions | Tel:   +64 4 495 8250   | Box 1195, Wellington
Awesome service    | Fax:   +64 4 495 8259   | New Zealand



> -----Original Message-----
> From: Tim Musson [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 29, 2001 4:24 AM
> To: [EMAIL PROTECTED]
> Subject: Re[5]: Best practice for config file use?
> 
> 
> Hey Jos,
> 
> I like this option the best of the 3, but it is still hard to give to
> a non programing person and not expect them to mess up setting the
> vars...
> 
> ie, => is what you separate things with, explaining which ' to
> use (' not `), end each parameter line with a ,
> 
> Wednesday, June 27, 2001, 6:15:54 PM, you wrote:
> 
> JIB> 2.    script that just uses one hashref to hold all the vars you
> JIB> need, let's call it config.pl too
> 
> JIB> ### config.pl ###
> JIB> $href = {
> JIB>     usr    => 'foo',
> JIB>     pwd  => 'bar',
> JIB>     host  => 'bleh.com',
> JIB> };
> 
> JIB> ### in your script you'd say: ###
> JIB> require 'config.pl'
> JIB> use vars qw($href);    #now it's just one variable 
> that's being used, still
> JIB> holding all your config data
> 
> -- 
> [EMAIL PROTECTED]
> Using The Bat! eMail v1.53d
> Windows NT 5.0.2195 (Service Pack 1)
> Life would be easier if I had the source code.
> 

Reply via email to