Posted on 2011-08-02 18:18
kongkongzi 阅读(1174)
评论(0) 编辑 收藏 引用 所属分类:
perl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 if (@ARGV < 1)
6 {
7 die "Usage:$0 path_name\n";
8 }
9
10
11 my $lineTotal = 0;
12
13 my @fileTypeArr = ("*.h", "*.cpp");
14 my $fileType;
15
16 foreach $fileType (@fileTypeArr)
17 {
18 # print "$fileType", "\n";
19
20 my $cmd = sprintf("find %s -name \"%s\"", $ARGV[0], $fileType);
21 my @fileArr = `$cmd`;
22 my $file;
23
24 foreach $file (@fileArr)
25 {
26 my $cmd = sprintf("wc -l %s", $file);
27 my @wcResult = `$cmd`;
28 # print $wcResult[0], "\n";
29 my @wcCol = split(/\s+/, $wcResult[0]);
30 $lineTotal = $lineTotal + $wcCol[0];
31 }
32 }
33
34 print $lineTotal, "\n";
35