简体   繁体   中英

Using XML::Twig locally without installing in Perl

I've written a relatively large script in Perl. A part of it should now be able to manipulate XML data. As far as I know XML::Twig would be the appropriate module for this kind of operation. Since the finished program does not run on my machine and I'm not able to install extra packages on the target system, I've decided to use XML::Twig locally. Hence I've copied it in a subfolder of my script, loaded it with use lib "$FindBin::Bin/foreign/"; (the Twig.pm was found there under the path foreign/XML/Twig.pm ) and use XML::Twig; .

On my Windows 7 Machine it worked perfectly. Now I've tried it on a Linux environment (Ubuntu), which is desired later, with the following error:

Can't locate loadable object for module XML::Parser::Expat in @INC

I really don't want to write my own library and I'm not able to install extra packages on this system (but it should work under those circumstances). Every suggestion would be appreciated.

Bits of XML::Parser::Expat are missing. Reinstall it.

It's part of the XML-Parser distribution on CPAN. Follow the instructions in the README file.

You need not only XML::Twig copied locally, but every other non-core module used by Twig (and used by the modules that are used by Twig, etc.).

One reason why it might work on your PC is that you have XML::Parser::Expat installed on that PC, but it's not on the Linux box. Include this (and all other dependent modules) in your "foreign" folder, and you can create a "portable" version of you script+modules.

To answer the op's follow-up comment to this initial post, XML::Parser::Expat is NOT part of XML::Parser, it's separate. See this section from the beginning of my copy of XML::Parser:

BEGIN {
  require XML::Parser::Expat;
  $VERSION = '2.41';
  die "Parser.pm and Expat.pm versions don't match"
    unless $VERSION eq $XML::Parser::Expat::VERSION;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM