in reply to PPI usage w/r/t documentation
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"'
|
|---|