1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/usr/local/bin/perl -w
use Getopt::Declare;
my $args = new Getopt::Declare <<EOARGS;
-f <filename:if> Parse file <filename>
EOARGS
@students = ();
@absent = ();
$data = q{
absmith,1234567,20
"aesmith, the other one",7635656,DNS
cat,dog,22.2
7637843,dejones,66.7
rmwilliams,288721,88
help me,I'm trapped,in the marks system
vtthan,872829,94
};
my $csv = <<'EOCSV';
<name:qs> , <id:+i> , <score:0+n> STD FORMAT [repeatable]
{ push @::students, {name=>$name, id=>$id, score=>$score} }
<id:+i> , <name:qs> , <score:0+n> VARIANT FORMAT [repeatable]
{ push @::students, {name=>$name, id=>$id, score=>$score} }
<name:qs> , <id:+i> , DNS DID NOT SIT [repeatable]
{ push @::absent, {name=>$name, id=>$id, score=>0} }
<other:/.+/> SOMETHING ELSE [repeatable]
{ print "Unknown entry format: [$other]\n"; }
EOCSV
if ($args->{"-f"})
{
my $args = new Getopt::Declare ($csv,[$args->{"-f"}]);
}
else
{
my $args = new Getopt::Declare ($csv,$data);
}
foreach ( @students )
{
print "$_->{id} ($_->{name}): $_->{score}\n";
}
foreach ( @absent )
{
print "$_->{id} ($_->{name}): ABSENT\n";
}
|