0
我之前問過這個問題,但沒有得到滿意的答案,因爲我沒有包含正確的示例。從多個perl腳本打印一個xml輸出,打印不同的xml輸出
我有多個使用xsl打印這些腳本的xml輸出的腳本。我想編寫一個主腳本來調用這些腳本併合並輸出並打印一個輸出。有人可以幫助我嗎?
#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;
這就是我想。
my $output = '';
my $example1 = `perl script1.pl --path=c:/cygwin/home/username/directory --debug=1`;
my $example2 = `perl script2.pl --path=c:/cygwin/home/username/directory --debug=1`;
open my $finaloutput, ">" $output or die "cant open the file";
print $finaloutput "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet
type=\"text/xsl\" href=\"final.xsl\"?>\n<OutputDestination>\n";
my @attachscript = ($example1, $example2);
for my $attached (@attachscript) {
print $finaloutput "<outputgoes_here_from_script> $attached
</outputgoes_here_from_script>
}
PRINT $finaloutput "</OutputDestination>"
close $finaloutput;
有沒有更好的方法來做到這一點?
你可以舉一個如何調用這些腳本的例子嗎? – jimtut
你好@jimtut我已經添加到頂部,我正在嘗試做什麼。 – Maxyie