develooper Front page | perl.beginners | Postings from December 2002

Executing a variable that contains perl code

Thread Next
From:
Dan Muey
Date:
December 17, 2002 14:25
Subject:
Executing a variable that contains perl code
Message ID:
D6D77DB239A2004BB08A240E2E71460D08F9AF@customer.infiniplex.net
Anybody know of any modules or ways to execute a variable that contains perl code as if it were part of the script?

IE do : print `/usr/bin/perl -e '$code_here'`;

Except be able to use variables/arrays/hashes/routines that are in the script  with that line

EG : print `/usr/bin/perl -e '$code_here'`;
Works great if $code_here is just a print statement or uses it's own vars/routines, etc
But I need to be able to have some code like this :

$joemama = "HI";
sub joe { print "Mama"; }

$code_here = 'print $joemama\;&joe\;'; # actually this var gets set with perl code in a mysql database 

print `/usr/bin/perl -e '$code_here'`;

output this :
HIMama

How can I get it to be able to use the script's vars and routines etc?

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About