2012-06-14 151 views
2

我已经写了一个多脚本,它以xml的形式返回输出。我有xsl文件,它将从xml为每个脚本打印出一张漂亮的表格。但是我需要编写一个脚本,在其中我调用所有这些多个脚本并创建一个输出。如何从一个perl脚本调用多个perl脚本并生成输出?

可以这样做吗?如果有的话,请给我一个例子,说明如何做到这一点。

#Example Script 1 

use strict; 
use warnings; 
use Data::Dumper; 
use XML::Simple; 
use Getopt::Long; 

my $output = ''; 
my $debug = 0; 
my $path; 
GetOptions('path=s' => \$path,'output=s' => \$output, 'debug=i' => \$d 
+ebug); 

if($output eq ''){ 
    die ("parameter --output=s is missing"); 
}  
open my $xmloutput, ">", $outputFile or die "can not open $outputFile 
+"; 
print $xmloutput "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-s 
+tylesheet type=\"text/xsl\" href=\"book.xsl\"?>\n<Books>\n"; 

my $parser = new XML::Simple; 
my $data = $parser->XMLin("$path"); 
print $xmloutput " <bookDetails> \n"; 
print $xmloutput " <bookName>$data</bookName> \n"; 
print $xmloutput " </bookDetails> \n"; 
print $xmloutput " </Books> \n"; 
close $xmloutput; 

实施例2

EXAMPLE 2 
use strict; 
use warnings; 
use Data::Dumper; 
use XML::Simple; 
use Getopt::Long; 

my $output = ''; 
my $debug = 0; 
my $path; 
GetOptions('path=s' => \$path,'output=s' => \$output, 'debug=i' => \$d 
+ebug); 

if($output eq ''){ 
    die ("parameter --output=s is missing"); 
}  
open my $xmloutput, ">", $outputFile or die "can not open $outputFile 
+"; 
print $xmloutput "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-s 
+tylesheet type=\"text/xsl\" href=\"Piano.xsl\"?>\n<Piano>\n"; 

my $parser = new XML::Simple; 
my $data = $parser->XMLin("$path"); 
print $xmloutput " <PianoDetails> \n"; 
print $xmloutput " <PianoName>$data</PianoName> \n"; 
print $xmloutput " </PianoDetails> \n"; 
print $xmloutput " </Piano> \n"; 
close $xmloutput; 

回答

0

听起来你需要使用反引号(')。

my $xmlout1 = `perl xmlscript1.pl`; 
my $xmlout2 = `perl xmlscript2.pl`; 
my $xmlout3 = `perl xmlscript3.pl`; 

1

写每个运行您的其他工具,以一个控制脚本。

如果子工具将其XML重新格式化输出写入STDOUT,则可以使用pipe open语法在控制脚本中捕获并重新格式化它。如果他们保存文件,你需要收集每个文件,按摩并合并它然后清理。

0

您可以按照require的顺序运行几个perl脚本,不需要使用系统调用。它可以做到这样的事情:

my @scripts_to_run = ('first.pl', 'second.pl', 'third.pl'); 
for my $script (@scripts_to_run) { 
    require $script; 
} 

...虽然东西告诉我,这应该实际上完成一个脚本,只是调用不同的参数。 )该脚本可以保存为模块,在编译时仅包含一次use,然后用任何参数(可能为),作为模块方法调用。

+0

你好Raina77ow,我提供了2个例子。因为我在这两个脚本中都使用getopt,所以我不确定如何在主脚本中调用这两个脚本并打印出结果。你能给我更多的细节吗?谢谢 – Maxyie