CoCalc Public Fileswww / cgi-bin / openwebmail / misc / test / debugdel.plOpen with one click!
Author: William A. Stein
1
#!/usr/bin/perl
2
#
3
# this uty removes the debug log line at the begining of all subroutine
4
# which were added by the debugadd.pl uty,
5
#
6
7
use strict;
8
if ($#ARGV<0) {
9
print "debugdel file1 file2 ...\n";
10
exit;
11
}
12
13
my $updatedfile=0;
14
my $totalremoval=0;
15
foreach my $script (@ARGV) {
16
my $content='';
17
my $removal=0;
18
print "remove debug code from $script ...";
19
open (F, $script);
20
while (<F>) {
21
my $line=$_;
22
if ($line=~/^sub .*{\s*/) {
23
$content.=$line;
24
while ((my $nextline=<F>)) {
25
if ($nextline !~ /^\s*log_time/) {
26
$content.=$nextline; last;
27
} else {
28
$removal++;
29
}
30
}
31
} else {
32
$content.=$line;
33
}
34
}
35
close(F);
36
37
if ($removal) {
38
if (open (F, ">$script")) {
39
print F $content;
40
close(F);
41
$updatedfile++;
42
$totalremoval+=$removal;
43
print "$removal line removed\n";
44
} else {
45
print "update err!\n";
46
}
47
} else {
48
print "\n";
49
}
50
}
51
52
print "$updatedfile file updated (total $totalremoval line removed)\n";
53