On Sat, Apr 07, 2001 at 01:22:14PM -0700, Peter Jay Salzman wrote:
[...]
> i'd like to read the file in and set variables according to what is in the
> file.  here's my attempt:
[Attempt to dereference by name stored in scalar snipped]
> 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";

I can't remember how to do this off the top of my head. This the answer to
this is in the Camel book, around page 15 if I recall correctly. Also try the
index entries for 'symbolic references' or 'soft references'. Here's
something similar that may help:

        #!/usr/bin/perl
        while ($LINE = <STDIN>) {
                if ($LINE =~ m/^(\w+)\s*=\s*(\w+)/) { &$1($2) }
        }
        sub mycmd { print $_[0] . "\n" }
        sub foo { print $_[0] . "\n" }

When run with input of:

        foo = bar
        mycmd = value

the output is:

        bar
        value

Sort of useless, but the possibilities should be obvious.

Out of curiosity, why don't you use a hash? That would be much easier!
Example:

        #!/uasr/bin/perl
        my %h;
        while ($LINE = <STDIN>) {
                if ($LINE =~ m/^(\w+)\s*=\s*(\w+)/) { $h{$1} = $2; }
        }

-- 
Henry House
OpenPGP key available from http://hajhouse.org/hajhouse.asc

PGP signature

Reply via email to