1

是否可以包含/获取另一个 perl 脚本,或者将其作为“子”启动?这有效,但看起来很难看:

测试2.pl:

print "I'm in test2.pl; args: @ARGV\n";

测试.pl:

#!/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;

X

$ ./test.pl a b c
I'm in test2.pl; args: a b c
4

2 回答 2

5

听起来你想要dooperator,虽然它也听起来像非常糟糕的设计。

这就是文档所说的。

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`;
于 2013-05-03T10:38:42.203 回答
1

您可以使用do在同一个解释器中运行另一个 Perl 脚本:

do 'test2.pl';

这将重用外部脚本中的命令行参数。要传递不同的参数,您可以@ARGV在本地覆盖,例如:

{
    local @ARGV = qw(par1 par2 par3);
    do 'test2.pl';
}
于 2013-05-03T10:44:37.547 回答