File: demo_csv

package info (click to toggle)
libgetopt-declare-perl 1.14-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 328 kB
  • sloc: perl: 1,386; makefile: 8
file content (59 lines) | stat: -rwxr-xr-x 1,210 bytes parent folder | download | duplicates (3)
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
55
56
57
58
59
#!/usr/bin/env perl

use strict;
use warnings;
no warnings qw(once);
use Getopt::Declare;

my $args = Getopt::Declare->new(<<EOARGS);
	-f <filename:if>	Parse file <filename>
EOARGS

my $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_spec = <<'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"})
{
	$args = Getopt::Declare->new($csv_spec,[$args->{"-f"}]);
}
else
{
	$args = Getopt::Declare->new($csv_spec,$data);
}

print "\nList of students:\n";
foreach ( @::students )
{
	print "   ".$_->{id}." (".$_->{name}."):	".$_->{score}."\n";
}

foreach ( @::absent )
{
	print "   ".$_->{id}." (".$_->{name}."):	ABSENT\n";
}