Andrew Stanley <[EMAIL PROTECTED]> said something to this effect on 11/15/2001:
> This code is used for reading a configuration file, which
> contains chains of variable / function calls on a bit of data.
> (It's part of a rules engine for different transaction types).
>
> I know that I can't do ${$data}, since symbolic references are
> compile time, whereas lexicals are runtime.  In a regexp, I
> could do the /ee construct to force "$arg1" to be interpreted,
> but I can't figure out exactly how to do it in code.  Doing:
>
> eval "$data";
>
> just prints nothing.
>
> The easiest solution:  Use a hash, which is what I'm leaning
> towards doing anyways.  But, by the same token, I'd like to
> know how to do this...

I got it work by using:

use strict;
use vars qw($arg1 $arg2 $arg3);
my $input = "a,b,c";

mySub($input);

sub mySub {
        my $args = shift;
        ($arg1,$arg2,$arg3) = split(/,/,$args);
        print "arg1 => $arg1\n";
        my $data = getSrcValue('+arg1');
        print "data => $data\n";
        no strict;
        my $d2 = ${$data};
        print "d2 => $d2\n";
}

sub getSrcValue {
        my $dat = shift;

        if (0) {
        } elsif ($dat =~ /^\*(.*)/) {
                return $dat;
        } elsif ($dat =~ /^\~(.*)/) {
                return \&$1;
        } elsif ($dat =~ /^\@(.*)/) {
                return $1;
        } elsif ($dat =~ /^\+(.*)/) {
                return $1;
        } else {
                return $dat;
        }
}

It seems to be that using a lexically scoped $arg1 causes the
symbolic reference to fail.  That doesn't make a lot of sense to
me, though.

Perl 5.6.1, BTW.

(darren)

--
Now imagine a Moebius vortex inside a spherical constant,
and you've got my cosmology.

Reply via email to