Preface
Sometimes there are these requirements:
1. count the number of rows of a file
2. Calculate the number of valid lines of a source code. Exclude empty and comment rows
3. Unify the quantity and number of files in a directory
Many languages can achieve these needs, but using Perl should be a good choice.
Number of lines reading files
It's easy to use Perl to read the total number of lines in a file (both empty lines and comments)
open(FILE ,<>); my $lines_counter = 0; while(<>){$lines_counter += 1; }print "lines: $lines_counter\n";
Of course, if it is simpler in Linux, you just need to input the following command:
wc -l filename
Number of lines of source code (number of spaces)
Count the number of lines of code in a source code file: input parameter: file path return: arrays of three elements; Total lines, empty lines, and comment lines respectively. Note: currently, this code is basically used in Java, C, and C ++, because the comments here process the following three types:
1. // line comment
2. Block comment
/*
*
*/
3. File comment
/**
*
*/
Complete code:
Source code line statistics Tool (Perl Version)
1.Code line counter
This is a paid software,
There are also free versions, but there are limits that only 10 files can be counted at a time.
:
Http://codelinecounter.bistonesoft.com/clcperl.htm
Download and install
The running interface is as follows:
2.Cloc
This should be a lot of tools.
It can count the number of various types of files in a path, the total number of spaces, code, and comments. It can also collect statistics on the status of files in a compressed package.
Project Introduction path:
Http://cloc.sourceforge.net/index.html#Basic_Use
Download path:
Http://sourceforge.net/projects/cloc/files/cloc/v1.60/
The Perl source code and the packaged EXE file are provided here.
Download the. exe file as a tool. The latest file name is cloc-1.60.exe
In command line mode, enter:
Cloc-1.60.exe file path or package name
The output result is similar: