#!/usr/local/bin/perl # File: form1sum # Function: Summarize results of form1.cgi # from email folder. # Author: Greg Johnson # Original: 23 March 1996, gkj # Perl: version 4.036 # # This is not a CGI script. # It runs at the Unix command prompt. # Standard input should be an email folder # containing the submissions from the form. # Standard output will be a formatted report. # # Example of usage: # # form1sum < mail/form1 | more # $form = 'form1'; $start = ":: START $form "; $start_length = length($start); require "ctime.pl" || die "Can't find ctime.pl $!"; $nsubmissions = 0; # main loop: read each record from standard input: while ($line = ) { # Find the next "START" record. if (substr($line,0,$start_length) eq $start) { &getdata ; } } # We've read all the records, now output them # sorted by the key: print $form," has ", $nsubmissions, " submissions at ",&ctime(time()); foreach $key (sort(keys(%rec))) { print $rec{$key},"\n"; } exit; sub getdata { # Get fields for one submission, from START to EOF. # Associative array %f contains value for one field, # where a field for form1 can be # email, title, fname, gname, comments # Associative array %rec has a unique sort key, and # contains the desired output records. chop $line; # $line = :: START formname ipaddr unixtime ($x,$x,$x,$ipaddr,$unixtime) = split(/\s/,$line); $time = substr(&ctime($unixtime),4,12); # Dispose of values from previous submission: $previous_item=''; undef %f; while ($line = ) { chop $line; # split the record on the first 3 blanks: ($mark,$item,$value) = ( $line =~ /(\S+) (\S+) (.*)/ ); # if line does not start with ::, # it's a continuation of previous item: if ($mark ne '::') { $f{$previous_item} .= " " . $line; } elsif ($item eq 'EOF') { last; } else { $f{$item} = $value; $previous_item = $item; } } # end while # # Save the accumulated fields in rec: $nsubmissions++; if ($f{'title'} eq '') {$tspace = ''} else {$tspace = ' '}; $key = "$f{'fname'} $f{'gname'} $nsubmissions"; $rec{$key} = sprintf( "%s\t%-30s\t%s%s%s %s\n%s\t%s", $time,$f{'email'},$f{'title'},$tspace, $f{'gname'},$f{'fname'}, $ipaddr,$f{'comments'} ); } # end subroutine getdata #