Plankton has asked for the wisdom of the Perl Monks concerning the following question:

I must be missing something about how to use XML::XPath::XMLParser::as_string. Here's what I am doing.

my $xp = XML::XPath->new(xml => $fpdomaininfo ); my $nodeset = $xp->find('//cidr-map'); foreach my $node ($nodeset->get_nodelist) { my $node_name = $node->findvalue ( '@name' ); my $ips_as_string = XML::XPath::XMLParser::as_string($node); $ips_as_string =~ s/ /:/g; # this prints nice list of ipaddresses # 127.0.0.1:198.168.1.1:198.168.1.2 print "<hr><hr>" . __LINE__ . "<br>" . $ips_as_string . "<hr>< +hr>\n";
The above code works fine as far as I can tell. A list if IP addresses is displayed separated by a ':'. Next I do this ...
my @ips = split /:/, $ips_as_string; # Dumper outputs this ... # 589 # $VAR1 = ' print "<hr><hr>" . __LINE__ . "<br>" . Dumper( @ips ) . "<hr>< +hr>\n";
The output is ...
589 $VAR1 = '
... next I do this ...
# this prints crap if XML in it !!! for my $ip ( @ips ) { print "$ip<br>"; }
... where the output include XML tags :/

Is there some subtle point to XML::XPath::XMLParser::as_string I am missing?

Replies are listed 'Best First'.
Re: Trouble using XML::XPath::XMLParser::as_string ?
by Anonymous Monk on Mar 16, 2011 at 01:29 UTC
Re: Trouble using XML::XPath::XMLParser::as_string ?
by aquarium (Curate) on Mar 16, 2011 at 03:33 UTC
    also..be careful mixing html tags with perl variables inside double quotes. i separate html from variables etc by single quoting all html and join or concatenate to other output. otherwise perl can sometimes misinterpret html tags as greater/smaller comparisons with your perl variables..and closing html tag slashes look like escape chars etc.
    the hardest line to type correctly is: stty erase ^H