in reply to Inspecting each element in a tree, specifically HTML::Tree

With better tools it becomes easier. No explicit recursion here, I just say what I want.

use Web::Query 'wq'; my $w = wq('http://www.guardian.co.uk'); my @headings = $w->find('h1')->text; # ( # "Coulson and Brooks face phone hacking prosecution", # " Usain Bolt: 'A lot of legends have come before me - but this +is my time' ", # )

Replies are listed 'Best First'.
Re^2: Inspecting each element in a tree, specifically HTML::Tree
by tobyink (Canon) on Jul 25, 2012 at 00:16 UTC
    use 5.010; use Web::Magic -quotelike => w; w(http://www.guardian.co.uk/) -> querySelectorAll('h1 a') -> foreach(sub { say $_->textContent })
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'