#!perl use strict; unless(scalar(@ARGV)==2){ print "\n$0 strips comment lines beginning with # from perl code"; print "\n - lines that begin with #! aren't stripped\n - use with caution, may strip more than comments!\n"; print "\nusage: perl unc.pl infile outfile"; print "\n set outfile to \"display\" to just show result\n"; exit } my$infile = shift; my$outfile = shift; open(IN,"< $infile") or die "\n $infile not found \n"; my@in = ; close(IN) or die "$!"; my%code = (); my($d,$c) = 0; my$t=scalar(@in); for(@in){ unless($_=~/^(\s+)?#[^!]/){ $code{$c}=$_; $c++ } else{$d++} } my@out = sort {$a <=> $b} keys %code; if($outfile eq 'display'){ for(@out){ print $code{$_} } &sum(); exit } open(OUT,"> $outfile") or die "\n $outfile write error \n"; for(@out){ print OUT $code{$_} } close(OUT) or die "$!"; &sum(); exit; sub sum{ print qq~\n $t lines read from $infile\n~; print qq~ $d comment lines detected in $infile\n~; print qq~ $c lines written to $outfile\n~; }