Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Config files

by Lucky (Scribe)
on Dec 10, 2001 at 22:47 UTC ( [id://130744]=note: print w/replies, xml ) Need Help??


in reply to Config files

You can make your own class to process config files. For plain config files it may looks like this:
package PlainConfig; use strict; use Carp; use vars qw($AUTOLOAD); sub new{ my $self=shift; my $config=shift || croak "There is no path parameter specified"; my $new={}; open CONFIG, $config || croak "Couldn't open config file - $config"; while (<CONFIG>){ s/^\s*//; next if (/^\s*#/ or /^$/); /^([^=\s]+)\s*=\s*([^\n\r]*)/; $new->{$1}=$2; } close CONFIG; bless $new, $self; return $new; } sub AUTOLOAD{ my $self=shift; my $attr=$AUTOLOAD; $attr=~s/(.*::)+//; return $self->{$attr}; } 1;
Then your script will be looks like this:
use PlainConfig; my $config=new PlainConfig; print "Username: ".$config->username."\n";
But there are many other approaches. Choose the best.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-16 17:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found