我之前曾问过这个问题,但没有得到满意的答案,因为我没有包含要查看的正确示例。
我有多个使用 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;
有没有更好的方法来做到这一点?