Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Hard time to make use of PPI

by brian_d_foy (Abbot)
on Apr 20, 2008 at 15:18 UTC ( #681785=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Hard time to make use of PPI
Select or Download Code
Re^2: Hard time to make use of PPI
by PetaMem (Priest) on Apr 20, 2008 at 15:42 UTC

    Thanks for your clarification. However, it's not "the docs" and "me", its only "the docs". What I presented was code from "the docs". So either they are fine, or they try to force to do everything else.

    Considering the fact that your given code differs from that in "the docs" and works, "me"'d be careful to give "the docs" a general absolution. ;-)

    Anyway, our unused subroutines identifier started just breathing.

    Bye
     PetaMem
        All Perl:   MT, NLP, NLU

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://681785]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2014-08-20 16:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (119 votes), past polls