in reply to tool to automatic update legacy code to English module usage

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.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: tool to automatic update legacy code to English module usage
by adamk (Chaplain) on Jul 07, 2009 at 08:48 UTC
    You want to look for PPI::Token::Magic probably.