ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/scripts/lcalc
Revision: 24
Committed: Tue Jul 26 21:46:39 2011 UTC (13 years, 1 month ago) by gpertea
File size: 1128 byte(s)
Log Message:
Line File contents
1 #!/usr/bin/perl
2 use strict;
3 use Getopt::Std;
4 use FindBin;use lib $FindBin::Bin;
5
6 my $usage = q/Usage:
7 lcalc [-M|-s]
8
9 -L : show maximum line length
10 -l : show minimum line length
11 -s : show sum and average of all numbers found in the first column
12 /;
13 umask 0002;
14 getopts('Llso:') || die($usage."\n");
15 my ($minlen, $maxlen, $sum, $count)=(999999999,0,0,0);
16 my $outfile=$Getopt::Std::opt_o;
17 if ($outfile) {
18 open(OUTF, '>'.$outfile) || die("Error creating output file $outfile\n");
19 select(OUTF);
20 }
21 # --
22 while (<>) {
23 s/[\n\r]+//s;
24 my $len=length($_);
25 $minlen=$len if ($len<$minlen);
26 $maxlen=$len if ($len>$maxlen);
27 next if $len==0;
28 my ($n)=(m/([eE\-\+\.\d]+)/);
29 $sum+=$n if length($n)>0;
30 $count++;
31 }
32 if ($Getopt::Std::opt_l || $Getopt::Std::opt_s) {
33 print "Min line length: $minlen\n";
34 }
35 if ($Getopt::Std::opt_L || $Getopt::Std::opt_s) {
36 print "Max line length: $maxlen\n";
37 }
38 if ($Getopt::Std::opt_s) {
39 print "$count non-empty lines found.\n";
40 my $avg=$sum/$count;
41 print "Sum : $maxlen (average: $avg)\n";
42 }
43
44 # --
45 if ($outfile) {
46 select(STDOUT);
47 close(OUTF);
48 }
49
50 #************ Subroutines **************

Properties

Name Value
svn:executable *