1: #!perl
2: use strict;
3:
4: unless(scalar(@ARGV)==2){
5: print "\n$0 strips comment lines beginning with # from perl code";
6: print "\n - lines that begin with #! aren't stripped\n - use with caution, may strip more than comments!\n";
7: print "\nusage: perl unc.pl infile outfile";
8: print "\n set outfile to \"display\" to just show result\n";
9: exit
10: }
11: my$infile = shift;
12: my$outfile = shift;
13:
14: open(IN,"< $infile") or die "\n $infile not found \n";
15: my@in = <IN>;
16: close(IN) or die "$!";
17:
18: my%code = ();
19: my($d,$c) = 0;
20: my$t=scalar(@in);
21: for(@in){
22: unless($_=~/^(\s+)?#[^!]/){
23: $code{$c}=$_;
24: $c++
25: }
26: else{$d++}
27: }
28: my@out = sort {$a <=> $b} keys %code;
29:
30: if($outfile eq 'display'){
31: for(@out){
32: print $code{$_}
33: }
34: &sum();
35: exit
36: }
37: open(OUT,"> $outfile") or die "\n $outfile write error \n";
38: for(@out){
39: print OUT $code{$_}
40: }
41: close(OUT) or die "$!";
42: &sum();
43: exit;
44:
45: sub sum{
46: print qq~\n $t lines read from $infile\n~;
47: print qq~ $d comment lines detected in $infile\n~;
48: print qq~ $c lines written to $outfile\n~;
49: }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: strip perl comment lines
by repson (Chaplain) on Feb 07, 2001 at 17:06 UTC | |
by epoptai (Curate) on Feb 07, 2001 at 17:48 UTC | |
|
Re: strip perl comment lines
by danger (Priest) on Feb 07, 2001 at 21:02 UTC | |
by quinkan (Monk) on Mar 05, 2001 at 16:14 UTC | |
by danger (Priest) on Mar 05, 2001 at 20:35 UTC | |
|
Re: strip perl comment lines
by merlyn (Sage) on Feb 07, 2001 at 19:55 UTC | |
by epoptai (Curate) on Feb 08, 2001 at 02:27 UTC | |
by japhy (Canon) on Feb 07, 2001 at 19:58 UTC | |
by merlyn (Sage) on Feb 07, 2001 at 20:03 UTC |