use strict; #counter for the number of lines we'll get my $count = 0; #first call our subroutine with program argument count_dir($ARGV[0]); #our recursive subroutine that counts .pl|.pm file-lines sub count_dir($) { my ($dir) = @_; #try to open directory passed or return if fail unless (opendir(DIR, $dir)) { print "\tCouldn't open dir: $dir\n"; return; } #get all files in directory my @files = readdir(DIR); #go through each file in dir foreach my $file (@files) { #move on if this file is a symbol next if (length($file) < 3); #if file is a .pl|.pm then count it's lines if ($file =~ /\.pl|\.pm/) { open(FILE, "<", "$dir\\$file") or print "\tCouldn't open $file to analyze\n"; while (<FILE>) { $count++; } } #otherwise if we can make this a directory lets dive into it elsif (opendir(TDIR, "$dir\\$file")) { count_dir("$dir\\$file"); } } } #print out our results print "\nLines of Perl code in directory:\t$count\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Perl LineCount
by merlyn (Sage) on Jul 18, 2002 at 16:06 UTC | |
by zoonek (Novice) on Jul 19, 2002 at 11:19 UTC | |
|
Re: Perl LineCount
by John M. Dlugosz (Monsignor) on Jul 18, 2002 at 18:18 UTC |