in reply to Can you create another perl interpreter within the current script?

Took me a little while, cause I am no closures and eval hero, but here is the trick...

This is the script holding your routines:
sub hello { return "Hello"; } sub world { return "world!"; } sub foo_bar { my ($foo, $bar) = @_; print "$foo $bar\n"; }

And this is the interpreter.
use strict; # Try to load code from a different perl script. Put it in a closure # and run run run... my $load_file = $ARGV[0]; # $flags my $in = 0; my @subs = (); my %routines = (); my %sub = (); open(IN, "<$load_file"); while (<IN>) { if ( /sub (\w+) \{/ ) { # hey! A routine has begun... $in = 1; push @subs,$1; $routines{$1} = ""; } if ( $in == 1 ) { if ( /\}/ ) { # sub ends. $in = 0; } else { s/^\s+//g; $routines{$subs[$#subs]} .= $_ unless /sub/; } } } close(IN); # mmm - we now have the internals of the routines in core. # let's see what we can do with them. print "You have these subs:\n"; foreach my $subs (keys %routines) { eval("\$sub{$subs} = sub { " . $routines{$subs} . " };"); print "\$sub{$subs} = sub { " . $routines{$subs} . " };\n" } $sub{'foo_bar'}->($sub{'hello'}->(), $sub{'world'}->()),"\n";


To be honest with you - I am kind of proud of myself *blush blush*

A righthanded-lefthand....
"Field experience is something you don't get until just after you need it."