lloder174 has asked for the wisdom of the Perl Monks concerning the following question:

/me does anyone know of a utility for parsing existing code into code that uses the variables implemented by the English module?
  • Comment on tool to automatic update legacy code to English module usage

Replies are listed 'Best First'.
Re: tool to automatic update legacy code to English module usage
by swampyankee (Parson) on Mar 09, 2009 at 22:37 UTC

    There should be no need to do so, unless it's to make downstream maintenance slightly easier. Write a Perl routine to replace the standard Perl variables, like $., by their English names, and remember to follow the performance-related advice in English.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Re: tool to automatic update legacy code to English module usage
by Limbic~Region (Chancellor) on Mar 10, 2009 at 00:17 UTC
    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

      You want to look for PPI::Token::Magic probably.
Re: tool to automatic update legacy code to English module usage
by sweetblood (Prior) on Mar 09, 2009 at 21:10 UTC
    Sure, perl!

    Sweetblood