|
发表于 2006-8-14 12:58:09
|
显示全部楼层
连夜替你炮制,还没有测试,个别地方可能有小问题,请自己测试修改。
$dirname = 'd:\java';
$counter=0;
$passcounter=0;
@Content="";
@Filename="";
@Linestotal=0;
@Blanklines=0;
@Commentlines=0;
opendir( DIR, $dirname) or die("Can't open");
foreach $filename (readdir(DIR))
{
if ($passcounter > 1)
{
$Linestotal[$counter]=0;
$Blanklines[$counter]=0;
$Commentlines[$counter]=0;
#print $filename . "\n";
$Filename[$counter]=$filename;
open ( FILE, $dirname . "\\" . $filename) || die ("Unable to open the file: $filename \n");
@Content = <FILE>;
$flag = 0;
foreach $i (@Content)
{
if ($i =~ m/\/\*/g)
{
$flag=1;
}
if ($flag == 1)
{
$Commentlines[$counter]++;
}
if ($i =~ m/\*\//g)
{
$flag = 0;
}
if ($i =~ m/\/\//g)
{
$Commentlines[$counter]++;
}
if ($i =~ m/^$/)
{
$Blanklines[$counter]++;
}
$Linestotal[$counter]++;
}
close(FILE);
$counter++;
}
$passcounter++;
}
$passcounter=0;
closedir(DIR);
#############result output#############
print "-------------------------------------------------------------------\n";
print " [File name] [Lines total] [Comments lines] [Blank lines] \n";
print "-------------------------------------------------------------------\n";
$counter=0;
foreach (@Filename)
{
print " $Filename[$counter]\t $Linestotal[$counter]\t \t $Commentlines[$counter]\t \t\t$Blanklines[$counter] \n";
$counter++;
} |
|