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