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

In reply to Re: Hard time to make use of PPI by brian_d_foy
in thread Hard time to make use of PPI by PetaMem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.