CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Making a sub of Perl code in a string

 



Henning Koch
Deleted

Jun 19, 2000, 11:58 PM

Post #1 of 3 (612 views)
Making a sub of Perl code in a string Can't Post

Code's more than a thousand words:

$code = "print 'hi world';";
$mysub = sub { $code }
$code = '';
&{$mysub};

Of course calling &{$mysub} would not print out "hi world" on my screen, because the code inside the sub is simply "$code", not "print 'hi world';".

So how can I expand $code into Perl code?

thanks,
Henning

PerlBall - Perl source compressor


Kanji
User

Jun 20, 2000, 5:33 AM

Post #2 of 3 (612 views)
Re: Making a sub of Perl code in a string [In reply to] Can't Post

Quickest way I can think of is to change ...

$mysub = sub { $code }

... to ...

$mysub = eval "sub { $code }";


Henning Koch
Deleted

Jun 20, 2000, 11:32 AM

Post #3 of 3 (612 views)
Re: Making a sub of Perl code in a string [In reply to] Can't Post

Hey and it actually works Smile Thanks a lot!

Henning

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives