在Perl中使用XPath

前端之家收集整理的这篇文章主要介绍了在Perl中使用XPath前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用Perl复制我的C#/ XPath代码Linux上的作用.我在 Perl & XML中复制并粘贴了例8-6中的代码.如果我理解正确,我应该可以运行该Perl代码,将此代码放在终端中

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

但是当我尝试运行Perl文件时,它不起作用.这是错误

[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.

我究竟做错了什么?我认为它与我的代码开头的XML和XPath名称有关.我是否需要安装一些东西才能使用XPath框架?我在RedHat 5.5上运行.

解决方法

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.

您没有安装XML :: XPath模块,或者Perl没有找到它.使用CPAN安装模块:

> cpan XML::XPath

或包裹经理:

> apt-get install libxml-xpath-perl

或者,如果它已经安装,说明PERL5LIB环境变量的位置:

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

@INC变量:

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

或者lib pragma:

use lib '/path/to/lib';

猜你在找的Perl相关文章