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

using script vars and routines when doing backtick execution of perl -e from within the script

Thread Next
From:
Dan Muey
Date:
December 17, 2002 08:43
Subject:
using script vars and routines when doing backtick execution of perl -e from within the script
Message ID:
D6D77DB239A2004BB08A240E2E71460D08F99D@customer.infiniplex.net
I have a need to get perl code from a database into a variabole and then execute it.
I can get it to work no problem if I'm just printing, or do my own vars and routines ( EG : $input contains $var = 1; and sub mon { print $var; } &mon; it wil print 1 )
But I can't use variables and subroutines that are in that script. ( EG : $var and sub do {..} below )
 
Does any one know a way to use the script's vars and routines if they are called form perl code found in the $input var below??
 
###################### script #####
#!/usr/bin/perl
 
$input = &get_perl_code_from_db;
 
$var = 1;
sub do { print "Monkey"; }
 
print `/usr/bin/perl -e '$input'`;
#################################
if $input just has : print "HI \n";
OUTPUT : HI
 
if $input has : print "Number $var \n";
OUTPUT : Number
 
if $input has &do;
OUTPUT : Undefined subroutine error
 
What I need to be able to do is use variable and subroutines that exist elsewhere in the script

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