-1

I have a Perl program to parse an input XML file and print values to an output text file.

It seems to work fine when I build with the DWIM Perl GUI, but when I build the same with ActivePerl it fails due to missing libraries.

Can someone help me converting the code to the ActivePerl equivalent?

The Perl code is

use strict;
use warnings;

use XML::LibXML;

open( my $File, '>', 'options.txt' );

my $filename = $ARGV[0];

my $parser = XML::LibXML->new();
my $xmldoc = $parser->parse_file( $filename );

for my $sample ( $xmldoc->findnodes( '/Releases/Release' ) ) {

    foreach my $child ( $sample->getChildnodes ) {

        if ( $child->nodeType() == XML_ELEMENT_NODE ) {
            print $File $child->textContent(), " ";
        }
    }

    print $File "\n";
}

My Input would be like (in XML)

<!-- Pre-Seed File for Script Generation -->
<Releases>
  <Release>
    <Family>F1L</Family>
    <ArVersion>3.2.2</ArVersion>
    <ReleaseVersion>C3.03.10.001</ReleaseVersion>
    <PackageType>FULL</PackageType>
  </Release>
  <Release>
    <Family>F1H</Family>
    <ArVersion>4.0.3</ArVersion>
    <ReleaseVersion>Ver4.03.20</ReleaseVersion>
    <PackageType>SPAL</PackageType>
  </Release>
</Releases>

The output should be

F1L 3.2.2 C3.03.10.001 FULL 
F1H 4.0.3 Ver4.03.20 SPAL 
Borodin
  • 126,100
  • 9
  • 70
  • 144
M. Ravi
  • 23
  • 4
  • Does it have to be active perl? because Strawberry perl comes with both `XML::Twig` and `XML::LibXML`. (I have largely given up on Activeperl because of the XML libraries being difficult) – Sobrique May 18 '17 at 15:55
  • I will need to build an executable from this file. I have an activeperl license. Hence it would be helpful if I can have an activeperl equivalent – M. Ravi May 18 '17 at 15:59
  • This looks like a library recommendation question then... – Sobrique May 18 '17 at 16:01
  • By the way, `foreach my $child ( $sample->getChildnodes ) { if ( $child->nodeType() == XML_ELEMENT_NODE ) { ... } }` can be replaced with `for my $child ( $sample->findnodes('*') ) { ... }` – ikegami May 18 '17 at 16:44

3 Answers3

1

There is no need for an "Activeperl equivalent". Perl code is cross-platform. Your code will work perfectly well under Active Perl. You just need to install the missing libraries. And there are plenty of answers on this site which can help you with that.

Dave Cross
  • 68,119
  • 3
  • 51
  • 97
0

"I have an activeperl license" You don't need an ActivePerl license—Perl is open source and free, unless you've forked out for the $1,000 per year "Business Edition"

You should either install XML::LibXML on your ActivePerl or you should carry on using DWIMPerl (which is basically Strawberry Perl with a few extra modules installed). If you're using ActiveState's Komodo then it should work fine with any current Perl

Borodin
  • 126,100
  • 9
  • 70
  • 144
  • To be fair, people pay ActiveState for support and the convenience of them building libraries, especially XS, for older versions of Perl on Windows etc. ... Not for Perl itself. – Sinan Ünür May 18 '17 at 16:48
0

ActivePerl is not a language; it's a Perl distribution. The code will run fine on ActivePerl as is.

>perl -v | perl -ne"print if /This|provided/"
This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x64-multi-thread
Binary build 1603 [296746] provided by ActiveState http://www.ActiveState.com

>perl a.pl a.xml

>type options.txt
F1L 3.2.2 C3.03.10.001 FULL
F1H 4.0.3 Ver4.03.20 SPAL
ikegami
  • 367,544
  • 15
  • 269
  • 518