Ahh, PPI. Great distribution... the best Perl parser next to perl itself :)

The first example should work without issue (passing in a reference to a string of Perl code). If you are saying the first example fails for you, please keep reading. If you are saying it DOES work for you, but only doesn't work when you use a var to wrap it, then I was just slightly misunderstood the issue, and the rest of this post is kind of invalid. The $ARGV[0] example was corrected by Athanasius, by sending in a reference to $ARGV[0] instead of sending it in directly.

Could you please try the below code and see if it compares to my output below? If it doesn't, can you please let us know, 1) Operating System and version, 2) perl version, 3) PPI version.

use warnings; use strict; use PPI; use PPI::Dumper; # string { my $doc = PPI::Document->new( \'print "hello, world!\n"' ) or die $!; print $doc->find_first('PPI::Statement') ."\n"; my $dumpr = PPI::Dumper->new($doc, qw(whitespace 0 comments 0)); $dumpr->print; } # string within scalar { my $run = 'print "goodbye, world!\n"'; my $doc = PPI::Document->new(\$run) or die $!; print $doc->find_first('PPI::Statement') ."\n"; my $dumpr = PPI::Dumper->new($doc, qw(whitespace 0 comments 0)); $dumpr->print; }

Output:

print "hello, world!\n" PPI::Document PPI::Statement PPI::Token::Word 'print' PPI::Token::Quote::Double '"hello, world!\n"' print "goodbye, world!\n" PPI::Document PPI::Statement PPI::Token::Word 'print' PPI::Token::Quote::Double '"goodbye, world!\n"'

In reply to Re: PPI usage w/r/t documentation by stevieb
in thread PPI usage w/r/t documentation by perl-diddler

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.