#!/usr/bin/perl # # cidpa: # generates pretty list of IDPA match scores for sort'ing # usage: cidpa match.file | sort +3 > match.txt # # I made this. -- prie, 7/4/2006 # # last modified: 8/20/2006 # # references: Learning Perl; Perl Cookbook; Perl in a Nutshell # ## match.file starts with numberOfStages, then lists shooter data ## sample match.file entry: ## ## First L. ## SSP/SS ## 13.36 16 ## 13.98 0 ## 23.78 9 ## 2.55 2 1*3 ## 3.31+3.33+.94 6 ## 14.20 5 # # grab first command-line argument in @ARGV: source file # $ARGV = shift; # function to add up a stage's score: time + pointsDown/2 + penalty # sub SCORE { return ( (eval $_[0]) + $_[1]/2 + (eval $_[2]) ); }; # open match datafile and read numberOfStages, then line-by-shooter-by-line: # get shooter's name, division, classification # for each stage, calculate score, and keep running totals & concatenations # pretty print (internally then externally): # format "time(down)" slightly better than "%11s" # open(matchFILE, "$ARGV"); chomp ( $numStages = ); while ( chomp ($name = ) ) { chomp ($info = ); $scoreList = ""; $totalTime = 0; $totalDown = 0; for ($i=1; $i<=$numStages; $i++) { chomp ( $record = ); @stage = split(" ", $record); $score = SCORE(@stage); $totalTime += $score; $totalDown += $stage[1]; $scoreList .= sprintf "%7.2f", $score; if ($stage[1] < 10) { $scoreList .= "(" . $stage[1] . ") "; # add a space to justify %11s } else { $scoreList .= "(" . $stage[1] . ")"; } } if ($totalDown < 10) { $totalTime .= "(" . $totalDown . ") "; # again, justify } else { $totalTime .= "(" . $totalDown . ")"; } printf "%6s %12s %11s", $info, $name, $totalTime; print "$scoreList\n"; } close(matchFILE); # # that's it.