On Jun 4, Satheesh Ramakrishnan said:
>How do I assign 1298b to some scalar variable from the string below.
>
>context_config_file = "1298b";
You probably want to use a hash of configuration variables, not a lot of
scalars.
There are modules for parsing simple config files, but if you want to do
it yourself, you have two main options:
1. make the config file a Perl program:
# require this for configuration data
%CONFIG = (
context_config_file => '1298b',
blah_blah_schtuff => 'john jacob jingleheimer-schmidt',
# ...
);
2. use a regex to get the key and value:
while (<CONFIG>) {
next if /^#/; # skip commented lines
my ($key, $value) = /(\S+)\s*=\s*(.*)/; # extract key/value
chop $value if $value =~ /^['"]/; # remove quotes if they're there
$CONFIG{$key} = $value;
}
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **