perl: run another script without exec/system
Is it possible to include/source another perl script, or launch it as a "sub"? This works, but looks ugly:
print "I'm in test2.pl; args: @ARGV\n";
#!/usr/bin/perl use File::Temp qw/tempdir/; use File::Copy qw/copy/; my $tmplib; use lib ($tmplib = tempdir()) . ( copy("./test2.pl", "$tmplib/test2.pm") ? "" : (die "$!") ); use test2;
$ ./test.pl a b c I'm in test2.pl; args: a b c
It sounds like you want the do operator, although it also sounds like very bad design.
This is what the documentation says.
do EXPR Uses the value of EXPR as a filename and executes the contents of the file as a Perl script.
do 'stat.pl'; is just like eval `cat stat.pl`;