I have asked this question before but did not get the satisfied answer as i did not include the proper example to look at.
I have multiple scripts that uses xsl to print xml output from those scripts. i want to write a one master script that calls those scripts and combine the out and print one output. could someone please help me with this?
#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;
EXAMPLE 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;
THIS IS WHAT I AM TRYING.
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;
Is there any better way of doing this ?
If script1 and script2 can’t be converted to Perl Modules and called directly (as functions) within your wrapper (or even just rewritten into a single new script), I’d consider just doing this in the wrapper:
You might need a “print” before the back-ticked system calls, but try it that way first. But, it’s not much different than your approach, just skipping the need to save the output from each script.