lloder174,
As I mentioned earlier in the CB, I think
PPI could be used to do this but it will take some work on your part. It is a general purpose tool for manipulating perl documents - not specialized to your task. Having never used it myself, the following falls far short of the mark (it did only take me about 10 minutes to come up with it though). Note: It doesn't see $/ so perhaps
PPI::Statement::Variable is only looking for declarations?
#!/usr/bin/perl
use strict;
use warnings;
use PPI;
my $script;
{
local $/ = undef;
$script = <DATA>;
}
my $doc = PPI::Document->new(\$script);
my $vars = $doc->find('PPI::Statement::Variable');
my @var_names = map { $_->variables } @$vars;
print "$_\n" for @var_names;
__END__
#!/usr/bin/perl
use strict;
use warnings;
my $foo = 'bar';
our $blah = 'asdf';
{
local $_ = 'hello world';
print $_, $/;
}
I was hoping there was a tutorial but I couldn't find one. It seems like PPI::Transform would be the right tool if you can figure out how to use it. I remember reading this article a few years ago - perhaps it will help/inspire you.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.