我想得到一个特定的字符串,例如
我已经写了一段代码,但遇到了一条错误消息:
Attempt to bless into a reference at /usr/share/perl5/XML/Twig.pm line 392.
我该如何解决?
代码:
use XML::Twig;
use LWP::Simple;
my $url = 'http://192.168.1.205:13000/status.xml';
my $twig = new XML::Twig(TwigRoots => {
'smsc/received' => sub {$author = $_[1]->text; }});
$twig->nparse( $url );
$twig->print;
最佳答案
nparse 为您处理 new
(因此是“n”),在这种情况下您想要的可能是 xparse
,或者让模块自行处理出去做这个:
my $url= 'http://192.168.1.205:13000/status.xml';
my $twig= XML::Twig->parse( twig_roots =>
{ 'smsc/received' => sub { $author= $_[1]->text;}},
$url
);
$twig->print; # I am not sure why you print the twig instead of just $author
关于xml - 如何使用 XML::Twig 从 URL 中提取一些 XML 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1524597/