Skip to content

Instantly share code, notes, and snippets.

@Niteshvgupta
Last active July 7, 2016 17:46
Show Gist options
  • Save Niteshvgupta/3076009fefbefb1001bd to your computer and use it in GitHub Desktop.
Save Niteshvgupta/3076009fefbefb1001bd to your computer and use it in GitHub Desktop.
A perl script to calculate a final grade based on the output of the "progress" command from Halligan computers at Tufts
#!/usr/bin/env perl
use strict;
use warnings;
my $num_args = $#ARGV + 1;
if ($num_args != 1) {
print "\nUsage: perl progress.pl class\n";
exit;
}
my $str = `progress $ARGV[0]`;
if ($str =~ /progress usage.+/) {
print $str;
exit;
}
else {
my @lines = split /\n/, $str;
my $num = 0;
my $total = 0;
foreach my $line(@lines) {
if ($line =~ /(\d+\.\d+)\sof\s+(\d+\.\d+)/) {
$num = $num + $1;
$total = $total + $2;
}
}
if ($total == 0) {
print "You don't seem to have any grades yet.\n";
exit;
}
my $grade = $num*100/$total;
print "Grade: $grade\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment