mipatel has asked for the wisdom of the Perl Monks concerning the following question:

hello, i have close to 3 perl scripts which generates the output in xml. with the use of xsl, my xml output is showing in table format.

I want to combine the output of these perl scripts and generate only ONE TABLE instead of 3 DIFFERENT tables.

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

here is the example 2 script

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;

How would i combine these two scripts and print one output from both scripts?

Replies are listed 'Best First'.
Re: printing one output from multiple scripts.
by chromatic (Archbishop) on Jun 18, 2012 at 22:58 UTC

    Pick a new root tag for the combined XML file and print its start and end around the two existing outputs, which become unique sections under the new root tag.

    For bonus points, refactor the resulting code to reduce duplication.


    Improve your skills with Modern Perl: the free book.

      hello, i am kind of new to perl. would it be possible if you can provide a quick example or a syntax that can be useD?

        Which parts are giving you trouble? It's a handful of lines of code and it uses nothing not already in your existing code. If you wrote that, you're more than capable of writing this.

        Give it a try. Play with what you have. If you get confused, show what you've done, and we can help you figure out what's going wrong.


        Improve your skills with Modern Perl: the free book.