[forwarded submission mistaken for admin request by majordomo -- rjk]


From: Andrew Stanley <[EMAIL PROTECTED]>
Date: Thu, 15 Nov 2001 10:33:01 -0500 (EST)
Subject: Mimicking /ee 
To: [EMAIL PROTECTED]

I have a bit of code that looks like:

use strict;

my $input = "a,b,c";

mySub($input);

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

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;
        }
}

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...

Cheers,

-Andrew

Andrew Stanley
http://www.cs.uml.edu/~astanley/

Reply via email to