That's certainly the way i would do it, but if you really want them stored
in scalars instead of hashes, then you can use eval.
In other words, instead of:
$conf{$key} = $val
you can say:
eval "\$$key = q/$val/"
Of course if your lines all start with '-', as you posted, then you'll have
to strip that character.
-----Original Message-----
From: Jos I. Boumans [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 25, 2001 2:34 PM
To: Bob Bondi; Beginners-perl
Subject: Re: Getting values from a file
assuming you are alright with storing them in a hash as key value pairs,
something like this will probably work for you:
open I, "$ARGV[0]" or die $!;
my %conf;
while(<I>){
chomp;
next unless $_;
my ($key,$val) = split /\s*=\s*/;
$conf{$key} = $val;
}
for (keys %conf) { print "$_ = $conf{$_}\n" }
or this, whatever you prefer:
open I, "$ARGV[0]" or die $!;
my %conf;
{ local $/; %conf = map{ chomp; $_ ? split /\s*=\s*/ :
undef }split/\n/,<I> }
for (keys %conf) { print "$_ = $conf{$_}\n" }
###################
both untested for speed, but if it's a small file it really shouldnt matter
hope this helps
Jos Boumans
> I'm planning on starting my perl script with a commandline argument, a
> filename. I open the file and parse through it line by line, OK, but I'm
> getting a blank on how to grab the value out of the file for a variable in
> the script. The file will read like:
> -TestClass = 3
> -TestCase = all
> -Proxy_IP = 255.255.255.255
> -Proxy_Port = 8080
> -Url = 101.101.101.10:80/test.html
>
> I'll have variable for each item above and I just want to fill-in the
> values.
>
> Is there a way to pull out those values and assign them properly?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]