The findvalue function in HTML::TreeBuilder::XPath returns a concatenation of any values found by the xpath query.
Why does it do this, and how could a concatenation of the values be useful to anyone?
The findvalue function in HTML::TreeBuilder::XPath returns a concatenation of any values found by the xpath query.
Why does it do this, and how could a concatenation of the values be useful to anyone?
When you call
findvalue, you're requesting a single scalar value. If there are multiple matches, they have to be combined into a single value somehow.From the documentation for HTML::TreeBuilder::XPath:
And from the documentation for Tree::XPathEngine::NodeSet:
An alternative would be to return the Tree::XPathEngine::NodeSet object so the user could iterate through the results himself, but the
findvaluesmethod already returns a list.For example:
Output:
Usually, though, it makes more sense to get a list of matches and iterate through them instead of doing dumb concatenation, so you should use
findvalues(plural) if you could have multiple matches.