On Sat, Apr 07, 2001 at 01:22:14PM -0700, Peter Jay Salzman wrote:
> i have a text file that holds what i want to be variables.   like:
> 
> Legacy = "/usr/local/bin/doomlegacy"
> PrboomClient = "blahblahblah"
> 
> i'd like to read the file in and set variables according to what is in the
> file.  here's my attempt:
> 
>       #!/usr/bin/perl -w
>       use diagnostics;
>       # use strict;
> 
>       my ($var, $val);
>       my $ConfigFile = 'config';
> 
>       open("FP", "< $ConfigFile");
>       while(<FP>) {
>               chomp;
>               /^(\w+)\s*=\s*\"(.*)\"/;
>               $var = $1;
>               $val = $2;
>               $$var = $val;
>               print $Legacy;
>       }
>       close(FP);
> 
> the trouble is, $Legacy is undefined.   i was under the impression that in
> perl, if you have a variable $hello which stored the word "dolly", then you
> could say:
> 
>       my $$hello = "clementine";
> 
> and that would assign the word "clementine" to the variable $dolly.
> obviously that's not happening.   help?
> 
> pete

Pete - your code works fine for me; but you should be certain that
'config' opens with no probs; i.e.,

open(FP, "< $ConfigFile") or die;  # Love saying that!

But Henry's suggestion of using a hash is definitely how I'd go about
it - mucking around with your name tables is not my idea of solid
coding - if you go with his suggestion, you can take the '#' out from
underneath your "use strict;"  :)

Micah

Reply via email to