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

Hello, I am little surprised the way Perl Stringifies (concatenating all the values of nodes) the NodeSet object. All I did is the following:
my $xp = XML::XPath->new(filename => 'test.xhtml'); my $nodeset = $xp->find('/html/body/p'); print "value is $nodeset\n";
My question is about the last print statement. How come when I try to print $nodeset which is an object resolved to the concatenation of all the values of the nodes ? I looked the NodeSet.pm and I think that to_literal method does this magic. But how Perl knows when to call this method. How does Perl knows the context of the usage ? That is how Perl knows that we are using it in print statement or regex so that it treats this as String otherwise as an object. Please point me to the code which is responsible for this. Thanks & Regards, Mohamed

Replies are listed 'Best First'.
Re: Stringification of XML::XPath::NodeSet
by choroba (Cardinal) on Oct 04, 2011 at 22:18 UTC
Re: Stringification of XML::XPath::NodeSet
by Khen1950fx (Canon) on Oct 05, 2011 at 00:53 UTC