http://qs321.pair.com?node_id=681785


in reply to Hard time to make use of PPI

Don't try to do it in one step. The find selects elements for the PDOM. Once you have the right elements, go through them to pull out the bit that you want.

use PPI; my $Document = PPI::Document->new( $ARGV[0] ); my $subs_ref = $Document->find( sub { $_[1]->isa('PPI::Statement::Sub') }); my @sub_names = map { $_->name } @$subs_ref; print "@sub_names\n";

The docs are fine. The find does the selection, but you're trying to force it to do everything else too. :)

Good luck,

Update: If you're just stealing snippets from the docs, then you are doing it wrong. I think you're talking about the snippet in the top-level PPI::Document docs, but you're assuming a lot about what it is saying. You need to read about the find method in PPI::Node, where the docs are quite clear. If a method doesn't do what you think it does, read the docs on that method. :)

Update 2: I've made the example in PPI::Document better.

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review