在 Perl 中使用 XPath [英] Using XPath with Perl
问题描述
我正在尝试使用 Perl 在 Linux 上复制我的 C#
/XPath
代码.我将示例 8-6 中的代码复制并粘贴到 Perl &XML.如果我理解正确,我应该能够运行该 Perl 代码,将此代码放入终端
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"
但是当我尝试运行 Perl 文件时,它不起作用.这是错误:
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.
我做错了什么?我认为这与代码开头的 XML 和 XPath 名称有关.我是否需要安装一些东西才能使用 XPath 框架?我在 RedHat 5.5 上运行.
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.
推荐答案
来自 perldiag
:
找不到 %s
您说要执行(或要求或使用)找不到的文件.Perl 在 @INC
中提到的所有位置查找文件,除非文件名包含文件的完整路径.也许您需要设置 PERL5LIB
或 PERL5OPT
环境变量来说明额外库的位置,或者脚本需要将库名称添加到 @INC代码>.或者,您可能只是拼错了文件名.参见
perlfunc
和 lib
中的 require
.
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 安装模块:
You don't have installed XML::XPath
module, or Perl not found it. Install module with CPAN:
> cpan XML::XPath
或使用包管理器:
> apt-get install libxml-xpath-perl
或者如果它已经安装,请使用 PERL5LIB
环境变量说明它的位置:
Or if it already installed say where it is with PERL5LIB
environment variable:
> PERL5LIB=/path/to/lib perl ...
@INC
变量:
BEGIN {
unshift(@INC, '/path/to/lib');
}
或 lib
编译指示:
use lib '/path/to/lib';
这篇关于在 Perl 中使用 XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!