Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using XPath with Perl

Tags:

perl

xpath

I am trying to replicate what my C#/XPath code does on Linux using Perl. I copied and pasted the code in Example 8-6 in Perl & XML. If I understand right, I should be able to run that Perl code, put this code in terminal

xmlPerl.pl mydatafile.xml "/inventory/category/item/name"

But when I try to run the Perl file, it doesn't work. Here is the error:

[root@Perl ~]# perl xmlPerl.pl
Can't locate XML/XPath.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at xmlPerl.pl line 3.
BEGIN failed--compilation aborted at xmlPerl.pl line 3.

What am I doing wrong? I think it has something to do with the XML and XPath names in the beginning of my code. Do I need to install something to use the XPath framework? I am running on RedHat 5.5.

like image 991
PolarisUser Avatar asked Oct 20 '25 05:10

PolarisUser


1 Answers

From perldiag:

Can't locate %s

You said to do (or require, or use) a file that couldn't be found. Perl looks for the file in all the locations mentioned in @INC, unless the file name included the full path to the file. Perhaps you need to set the PERL5LIB or PERL5OPT environment variable to say where the extra library is, or maybe the script needs to add the library name to @INC. Or maybe you just misspelled the name of the file. See require in perlfunc and lib.

You don't have installed XML::XPath module, or Perl not found it. Install module with CPAN:

> cpan XML::XPath

or with package manager:

> apt-get install libxml-xpath-perl

Or if it already installed say where it is with PERL5LIB environment variable:

> PERL5LIB=/path/to/lib perl ...

@INC variable:

BEGIN {
    unshift(@INC, '/path/to/lib');
}

or lib pragma:

use lib '/path/to/lib';
like image 184
Denis Ibaev Avatar answered Oct 22 '25 04:10

Denis Ibaev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!