I was looking over the PPI set of modules and am wondering if anyone uses it in the format:
# Create a document from source $Document = PPI::Document->new(\'print "Hello World!\n"');
I've tried several variations using vars, double and single quotes, but have been unable to get it to parse anything from memory. It *does* work if I give it a file, but the example above doesn't seems to work -- which seems pretty basic.

I'm wanting to use it for memory-based input and no files are involved, For example, I might want to parse the same line 2 different ways (maybe with a trailing semicolon, or w/o, or some other way).

I'm wondering what syntax is suppose to work -- I also pointed out that the documented example doesn't work in their issue database, but no response on that. So does anyone have any working examples? My basic framework (in a file called ppi_dump) looks like:

#!/usr/bin/perl use warnings; use strict; # use utf8; use open IN=>q(:utf8); use open OUT=>q(:utf8); use PPI; use PPI::Dumper; use P; P "parse: %s", $ARGV[0]; my $doc=PPI::Document->new($ARGV[0]); my $dumpr=PPI::Dumper->new($doc, qw(whitespace 0 comments 0)); # .my $toks = $dumpr->list; # for indirect access... $dumpr->print;

A working example should suffice to jumpstart this -- from the documentation, I would have thought a string would have worked for my "arg", like:

> ppi_dump 'print "Hello World!\n"' parse: print "Hello World!\n" Can't call method "list" on an undefined value at ./ppi_dump line 14.

FWIW, if I give it a filename, it shows the content of the file, parsed, but the parse from string is the issue.

Tnx...


In reply to 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.