l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 20: Web Application Hacking: How to Make and Break Security on the Web
Next Installfest:
TBD
Latest News:
Oct. 10: LUGOD Installfests coming again soon
Page last updated:
2001 Dec 30 17:04

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] perl question - variable holding a variable name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] perl question - variable holding a variable name


  • Subject: Re: [vox-tech] perl question - variable holding a variable name
  • From: Micah Cowan <micMAPSah@cowanbox.com>
  • Date: Mon, 09 Apr 2001 11:13:51 -0700
  • References: 20010407132214.A11971@dirac.org

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


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.