nitin1704 has asked for the wisdom of the Perl Monks concerning the following question:
I need to add a few lines at the beginning of every subroutine, in about 50 perl files, each having about 10 subroutines.
I tried regular expressions as follows:
my $allText = read_file($file); my $call = <<'END'; my @mars_caller = caller(0); mars::print::call(\@mars_caller, \@_); END $allText =~ s/([\n\s]+sub[\n\s]+.*?{)/\1$call/sg;
However this method is not so reliable as it found the word "sub" in a comment or print statement followed by some lines and then found a "{" somewhere else in the program and replaced that with the substitution string. Instead it should just find the real subroutine definitions.
I hope I've made my problem clear. Is there a better way to do this? Thanks for helping!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Changing every subroutine in many perl scripts
by toolic (Bishop) on Jul 24, 2012 at 15:07 UTC | |
by nitin1704 (Sexton) on Jul 25, 2012 at 02:43 UTC | |
by nitin1704 (Sexton) on Jul 25, 2012 at 04:17 UTC | |
by GrandFather (Saint) on Jul 25, 2012 at 22:24 UTC | |
|
Re: Changing every subroutine in many perl scripts
by Jenda (Abbot) on Jul 25, 2012 at 08:19 UTC | |
by nitin1704 (Sexton) on Jul 26, 2012 at 03:36 UTC | |
by chromatic (Archbishop) on Jul 26, 2012 at 05:55 UTC | |
by nitin1704 (Sexton) on Jul 26, 2012 at 09:06 UTC | |
|
Re: Changing every subroutine in many perl scripts
by Anonymous Monk on Jul 24, 2012 at 18:10 UTC |