I am parsing an html content by using HTML-TreeBuilder-XPath
in Perl . i have got the xpath location of the data i need. The issue i am facing is ,There are several matches of the xpath $html->findnodes()
which is returned by single result ,but i need to print it one by one. Need some suggestion .Thank you.
Asked
Active
Viewed 71 times
1

Balakumar
- 650
- 1
- 12
- 29
2 Answers
4
You can iterate over using
for my $node (@$paraelements) { ..... }
A more complete example
use HTML::TreeBuilder::XPath;
my $tree= HTML::TreeBuilder::XPath->new;
$tree->parse_file( "mypage.html");
my $paraelements= $tree->findnodes( '//p') ;
for my $node (@$paraelements) {
say $node->as_HTML() ;
}

justintime
- 3,601
- 4
- 22
- 37
0
It returns a reference to a list (ARRAYREF). To get back the list, put a @ before the variable to tell Perl to treat that as the [location/memory address] of the list just as JIT's sample code

Ryan Phan
- 41
- 4