in reply to Re^2: Changing every subroutine in many perl scripts
in thread Changing every subroutine in many perl scripts
Okay, I got it now, after going through the CPAN documentation a bit more.
use strict; use warnings; use PPI; my $file = '/path/to/perl/script.pl'; my $Document = PPI::Document->new($file) or die "oops"; for my $sub ( @{ $Document->find('PPI::Statement::Sub') || [] } ) { unless ( $sub->forward ) { my @elements = $sub->children; for ( my $i = 0 ; $i < @elements ; $i++ ) { if ( ref $elements[$i] eq "PPI::Structure::Block" ) { $elements[$i]->start->add_content("my mars code"); } } } } $Document->save($file.".new");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Changing every subroutine in many perl scripts
by GrandFather (Saint) on Jul 25, 2012 at 22:24 UTC |