savannah-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Savannah-cvs] administration/lists stats.pl


From: Elfyn McBratney
Subject: [Savannah-cvs] administration/lists stats.pl
Date: Sat, 11 Sep 2004 22:11:21 -0400

CVSROOT:        /cvsroot/administration
Module name:    administration
Branch:         
Changes by:     Elfyn McBratney <address@hidden>        04/09/12 02:06:04

Modified files:
        lists          : stats.pl 

Log message:
        improve.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/administration/administration/lists/stats.pl.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: administration/lists/stats.pl
diff -u administration/lists/stats.pl:1.1 administration/lists/stats.pl:1.2
--- administration/lists/stats.pl:1.1   Sun Sep 12 01:27:20 2004
+++ administration/lists/stats.pl       Sun Sep 12 02:06:04 2004
@@ -21,39 +21,66 @@
 use warnings;
 
 use File::Basename;
+use Data::Dumper;
 
 # basename of this script
 my $prog = basename $0;
 
-# input file
-my $file = shift @ARGV || die "Usage: $prog [input-file]\n";
+my ($file, %stats);
+$file = shift @ARGV || die "Usage: $prog [input-file]\n";
+&stats_parse($file, \%stats);
+print Data::Dumper->Dump([\%stats], ['stats']);
 
-# try and open the file, and slurp in it's content
-my @input;
-open IN, $file or die "failed to open $file";
address@hidden = <IN>;
-close IN or die "failed to close $file";
-
-my %sect;
-my $cur;
-
-foreach (@input) {
-    next if /^\s*?$/ || /^#\-/;
-    chomp;
-
-    if (/^#:(.+)$/) {
-       $cur = $1;
-    } elsif (/^([A-Za-z0-9\-]+)$/) {
-       $sect{$cur}++;
-    } elsif (/^([A-Za-z0-9\-]+)\s+\(([A-Za-z]+)\)$/) {
-       $sect{$cur}++;
-    } elsif (/^([A-Za-z0-9\-]+)\s+\(([A-Za-z]+)(.+)\)$/) {
-       $sect{$cur}++;
-    } else {
-       die "input error near: $_";
-    }
+sub my_trim {
+    my $str = shift @_;
+
+    $str =~ s/^\s*?//;
+    $str =~ s/\s*?$//;
+
+    return $str;
 }
 
-foreach (keys %sect) {
-    printf "%s:\n\t%d\n\n", $_, $sect{$_};
+sub stats_parse {
+    my ($file, $stats) = @_;
+    my @lines;
+    my $cur_section = '';
+    my $cur_description = '';
+    my $lineno = 0;
+
+    # open the file, and slurp in it's content
+    open IN, $file or die "failed to open $file";
+    @lines = <IN>;
+    close IN or die "failed to close $file";
+
+    # walk though each line and attempt to parse it
+    foreach (@lines) {
+       $lineno++;
+
+       $_ = &my_trim($_);
+       next if /^$/;
+
+       if (/^\#:\s+(.+)/) {
+           $cur_section = $1;
+       } elsif (/^\#\-\s+(.+)/) {
+           $cur_description = $2;
+       } else {
+           die "not in a section on line $lineno near: $_" if $cur_section eq 
'';
+           $stats{$cur_section} = {} if !exists $stats{$cur_section};
+
+           if (/^([A-Za-z0-9\-]+)$/) {
+               $stats{$cur_section}{'count'}++;
+           } elsif (/^([A-Za-z0-9\-]+)\s+\(([A-Za-z]+)\)$/) {
+               $stats{$cur_section}{'count'}++;
+               $stats{$cur_section}{$1}{'evaluator'} = "\L$2";
+           } elsif (/^([A-Za-z0-9\-]+)\s+\(([A-Za-z]+)(.+)\)$/) {
+               $stats{$cur_section}{'count'}++;
+               $stats{$cur_section}{$1}{'evaluator'} = "\L$2";
+               $stats{$cur_section}{$1}{'comment'} = "\L$3";
+               $stats{$cur_section}{$1}{'comment'} =~ s/;\s+//;
+           } else {
+               die "input error on line $lineno near: $_";
+           }
+       }
+    }
 }
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]