删除C语言代码中的所有注释

#!/usr/bin/perl -w
my $c_file = $ARGV[0];
my $c_file_out = $ARGV[1];
open(CF,"<$c_file");
my @cf = <CF>;
close CF;
my $cf = join '',@cf;
$cf =~ s/((?<=\n)|^)[ \t]*\/\*.*?\*\/\n?|\/\*.*?\*\/|((?<=\n)|^)[ \t]*\/\/[^\n]*\n|\/\/[^\n]*//gs;
open(OUT,">$c_file_out");
print OUT "$cf";
close OUT;

编程技巧