On Mon, Apr 09, 2001 at 06:05:13PM -0700, Mark K. Kim wrote:
> Sometimes you obtain a variable name in a string, like in a variable
> called "$varname" (without the quotes) and you want to manipulate that
> variable. This can happen if you're writing your own language (call it
> the "LUG" language), and you want LUG programs to be able to access the
> interpreter's variables directly.
[example snipped]
Okay, this make sense.
You can do almost the same thing using a global hash, though. I.e.,
#!/usr/bin/perl
%Vars = {}; # declare empty hash
.
.
.
sub read_vars_from_string {
while ($line = STDIN) {
chomp $line;
if ($line =~ m/\$([A-z]+) *= *([A-z0-9]+)/) # read declarations of form
# $foo = bar
{ $Vars{$1} = $2; }
}
}
--
Henry House
OpenPGP key available from http://hajhouse.org/hajhouse.asc
PGP signature