-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.pl
More file actions
68 lines (52 loc) · 2.03 KB
/
reader.pl
File metadata and controls
68 lines (52 loc) · 2.03 KB
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
60
61
62
63
64
65
66
use strict;
use warnings;
use YAML::XS;
use lib 'lib';
use Data::CSV::Reader;
# read sequentially
my $reader = Data::CSV::Reader->new(
check_type => 0,
);
$reader->def("nodedef> a;b; c VARCHAR(44);test:a;t;test:e\n");
print Dump $reader->def;
print Dump $reader->row('4;"4""4";4;6;9;8\n');
print "\n\n";
# read all
print Dump $reader->all(
"a;b;c INTEGER;test:a;t;test:e", # first line must be the definition
'4;4;4;"6""6";9;8'
);
my $reader = Data::CSV::Reader->new(
check_type => 0,
text_csv => {
sep_char => ";",
quote_char => "'",
binary => 1,
eol => "\n",
}
);
$reader->def("nodedef> a;b; c VARCHAR(44);test:a;t;test:e\n");
print Dump $reader->def;
eval {print Dump $reader->row("4;'4''4';4;6;9;8\n")};
warn "".$reader->text_csv->error_diag () if $@;
# indirect constructor
use Data::CSV;
my $reader = Data::CSV->reader(text_csv => {
sep_char => ",",
quote_char => "'",
binary => 1,
eol => "\n",
allow_loose_quotes => 0,
allow_loose_escapes => 0,
});
# direct read all
#
# use Data::CSV;
# print Dump Data::CSV::read(...);
$reader->def("nodedef> id VARCHAR,name VARCHAR,url VARCHAR,accept VARCHAR,refuse VARCHAR,seed_distance INTEGER,status VARCHAR,title VARCHAR,pages INTEGER,links INTEGER,score:text:verbes,score:text:stop words,score:text:ina,score:text:tf1\n");
print Dump $reader->def;
print Dump $reader->row("'g\"'roupe-tf1.fr-ae2d3dac5bee7e73',groupe-tf1.fr,http://www.groupe-tf1.fr/ressources-humaines/,,,1,valid,,1,,,,,\n");
eval {print Dump $reader->row("vie-publique.fr-d53067984bed2d61,vie-publique.fr,'https://mon.vie-publique.fr/?a=se&v=2&f=clip&tl=bk&u=http://service-public.fr/&t=service-public.fr,%20le%20site%20officiel%20de%20l''administration%20française&x=&tag=&sw=1',,,3,valid,,1,,,,,\n");};
die "".$reader->text_csv->error_diag () if $@;
#print Dump $reader->row("groupe-tf1.fr-ae2d3dac5bee7e73,groupe-tf1.fr,http://www.groupe-tf1.fr/ressources-humaines/,,,1,valid,,1,,,,,\n");
#print Dump $reader->row("lexpress.fr-1feb11e5765e1ed3,lexpress.fr,'http://l''express.fr/',,,3,valid,,10,151,880,87516,,220\n");