Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-25 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found