rendered paste body#!/usr/bin/perl
my $student = $ARGV[0]; # Student ID
my $code = $ARGV[1]; # Code
my $num_qns = $ARGV[2]; # Number of questions
my @grades = ();
my @idxs = ();
my $ctr =0;
# Display what we got
sub show_grades {
my $i =0;
print "\n$student $code ";
foreach (@grades){
print $idxs[ $i++ ] .":$_ , ";
}
print "\n";
}
# infintite loop
while(1){
last if $ctr > $num_qns-1;
print "[Enter (a-f)+ ,(x = empty), for fixes (Ex: 42 a), 's' - show ] ". ($ctr+1). ": ";
my $input = <STDIN>;
chomp ($input);
print " ===> <$input>";
if( $input eq 's' or $input eq 'S' ){ # Show current list
show_grades();
next;
}
elsif( $input =~ /^[a-f|x|X]+/ ){ # Normal entry
if( $input eq 'x' or $input eq 'X'){
$input = "-";
}
push @grades, $input;
push @idxs, ++$ctr;
}
elsif( $input =~ /^(\d+)\s+([a-f]+)/ ){ # Correction
my $idx = $1 - 1;
$grades[$idx] = $2;
}
print "\n";
}
&show_grades();