![]() |
|
|
| Subject:
Linux grade emailing script
Category: Computers > Programming Asked by: script101-ga List Price: $20.50 |
Posted:
03 Sep 2005 16:37 PDT
Expires: 03 Sep 2005 21:37 PDT Question ID: 564017 |
I need a script (bash, perl or whatever) that takes a csv file called grades.csv and emails students their grade when I run the script. csv file is in the following format: "ID","Name","Email", "Quiz 1", "Quiz 2", "Exam 1", "Total", etc 1234, "John Doe","jdoe@umn.edu",12,15,86,74 4567, "John Doe2","jdoe2@umn.edu",4,12,74,89 The student should recieve and email in the following format: Subject: Your Calc grade: Dear John Doe, your grade in class is: Quiz 1|Quiz 2|Exam 1|Total| 12 |15 |86 |74 | --------------------------- If you have any questions regarding your grade please contact me ASAP! | |
| |
| |
| |
|
|
| There is no answer at this time. |
|
| Subject:
Re: Linux grade emailing script
From: bozo99-ga on 03 Sep 2005 18:47 PDT |
I hope this isn't messed up by word-wrap or web presentation.
#!/usr/bin/perl -w
require 5.0;
@titles=();
# might want an absolute pathname for the csv file
open(GRADES, "<grades.csv") or die("cannot open grades.csv file");
while (<GRADES>) {
chomp();
@f=split(/,/);
foreach $f (@f) {
die("NEED QUOTING - COMMAS IN THE FIELDS MAKE THIS MORE
COMPLICATED") if ($f =~ /,/);
if ($f =~ /^\s*"(.*)"\s*$/) {
# removed quotes and whitespace round the string
$f=$1;
}
}
if ( (0==@titles) && ("ID" eq $f[0]) ) {
@titles=@f;
shift @titles;
shift @titles;
shift @titles;
for ($i=0; $i < @titles; $ i++) {
# length of each title is recorded for use in counting whitespace later
$tl{$i}=length($titles[$i]);
}
next;
}
@scores=@f;
shift @scores;
shift @scores;
shift @scores;
if (@titles != @scores) {
printf("Warning: Number of titles does not equal number of
scores for %s (%s)\n", $f[0], $f[1]);
}
# Check pathname of sendmail is correct - "/usr/sbin/sendmail" on some systems.
open(EMAIL, "|/usr/lib/sendmail -oi -t") or die("opening EMAIL
($f[0]) $!") or die("failed email");
printf(EMAIL "To: %s\n", $f[2]);
printf(EMAIL "Subject: Your Calc grade:\n");
printf(EMAIL "\n\nDear %s, your grade in class is:\n", $f[1]);
# show titles
foreach $t (@titles) {
printf(EMAIL "%s|", $t);
} # show scores
# I'm assuming these are always numeric as in your example and not
text like "absent".
for ($i=0; $i < @scores; $ i++) {
$s=$scores[$i];
$pad=$tl{$i} -length($s);
printf(EMAIL "%d", $s);
printf(EMAIL "%s|", " "x$pad);
}
printf(EMAIL "\n");
# underline of correct length
for ($i=0; $i < @titles; $ i++) {
$pad=$tl{$i}+1;
printf(EMAIL "%s", "-"x$pad);
}
printf(EMAIL "\n");
printf(EMAIL "If you have any questions regarding your grade
please contact me ASAP!\n");
close(EMAIL) or die("failed email");
}
close(GRADES);
exit(0); |
| Subject:
Re: Linux grade emailing script
From: bozo99-ga on 03 Sep 2005 18:52 PDT |
The word-wrap is pretty obvious so I don't expect it to cause trouble. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |