in reply to Config files
Then your script will be 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;
But there are many other approaches. Choose the best.use PlainConfig; my $config=new PlainConfig; print "Username: ".$config->username."\n";
|
|---|