line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Process; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
4073
|
use strict; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
183
|
|
4
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
122
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
31
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
346
|
|
7
|
5
|
|
|
5
|
|
2595
|
use English qw(-no_match_vars); |
|
5
|
|
|
|
|
7673
|
|
|
5
|
|
|
|
|
28
|
|
8
|
5
|
|
|
5
|
|
4015
|
use File::Process::Utils qw(:booleans :chars); |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
1109
|
|
9
|
5
|
|
|
5
|
|
2440
|
use IO::Scalar; |
|
5
|
|
|
|
|
20342
|
|
|
5
|
|
|
|
|
232
|
|
10
|
5
|
|
|
5
|
|
36
|
use Scalar::Util qw( openhandle ); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
233
|
|
11
|
5
|
|
|
5
|
|
31
|
use Data::Dumper; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
226
|
|
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
31
|
use parent qw( Exporter ); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
26
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our %DEFAULT_PROCESSORS = ( |
18
|
|
|
|
|
|
|
pre => \&_pre, |
19
|
|
|
|
|
|
|
next_line => \&_next_line, |
20
|
|
|
|
|
|
|
filter => \&_filter, |
21
|
|
|
|
|
|
|
process => \&_process, |
22
|
|
|
|
|
|
|
post => \&_post, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
5
|
|
629
|
use parent qw(Exporter); |
|
5
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
24
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our @EXPORT = qw( process_file ); ## no critic (ProhibitAutomaticExportation) |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
30
|
|
|
|
|
|
|
post |
31
|
|
|
|
|
|
|
pre |
32
|
|
|
|
|
|
|
process |
33
|
|
|
|
|
|
|
process_csv |
34
|
|
|
|
|
|
|
filter |
35
|
|
|
|
|
|
|
next_line |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
39
|
|
|
|
|
|
|
'booleans' => [qw($TRUE $FALSE $SUCCESS $FAILURE)], |
40
|
|
|
|
|
|
|
'all' => \@EXPORT_OK, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
caller or __PACKAGE__->main(); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
######################################################################## |
46
|
|
|
|
|
|
|
sub process_csv { |
47
|
|
|
|
|
|
|
######################################################################## |
48
|
9
|
|
|
9
|
1
|
26161
|
require File::Process::Utils; |
49
|
|
|
|
|
|
|
|
50
|
9
|
|
|
|
|
33
|
return File::Process::Utils::process_csv(@_); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
######################################################################## |
54
|
|
|
|
|
|
|
sub process_file { |
55
|
|
|
|
|
|
|
######################################################################## |
56
|
18
|
|
|
18
|
1
|
17779
|
my ( $file, %args ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
18
|
|
|
|
|
41
|
my $chomp = $args{'chomp'}; |
59
|
|
|
|
|
|
|
|
60
|
18
|
|
33
|
|
|
68
|
$args{'file'} = $file || $EMPTY; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my %processors |
63
|
18
|
|
|
|
|
36
|
= map { ( $_, $args{$_} ) } qw( pre filter next_line process post ); |
|
90
|
|
|
|
|
189
|
|
64
|
|
|
|
|
|
|
|
65
|
18
|
|
|
|
|
53
|
foreach (qw( pre filter next_line process post)) { |
66
|
90
|
100
|
|
|
|
179
|
if ( !$processors{$_} ) { |
67
|
68
|
|
|
|
|
123
|
$processors{$_} = $DEFAULT_PROCESSORS{$_}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
18
|
|
|
|
|
43
|
$args{'default_processors'} = \%DEFAULT_PROCESSORS; |
72
|
|
|
|
|
|
|
|
73
|
18
|
|
|
|
|
53
|
my ( $fh, $all_lines ) = $processors{'pre'}->( $file, \%args ); |
74
|
|
|
|
|
|
|
|
75
|
18
|
50
|
33
|
|
|
114
|
if ( !$fh || !ref $all_lines ) { |
76
|
0
|
|
|
|
|
0
|
croak |
77
|
|
|
|
|
|
|
"invalid pre processor return values: wanted file handle, array ref\n"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
18
|
|
|
|
|
29
|
LINE: while (1) { |
81
|
144
|
|
|
|
|
363
|
my $current_line = $processors{'next_line'}->( $fh, $all_lines, \%args ); |
82
|
144
|
100
|
|
|
|
465
|
last LINE if !defined $current_line; |
83
|
|
|
|
|
|
|
|
84
|
126
|
|
|
|
|
180
|
$args{'raw_count'}++; |
85
|
|
|
|
|
|
|
|
86
|
126
|
|
|
|
|
228
|
foreach my $p ( @processors{qw( filter process )} ) { |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$current_line |
89
|
250
|
|
|
|
|
349
|
= eval { return $p->( $fh, $all_lines, \%args, $current_line ); }; |
|
250
|
|
|
|
|
485
|
|
90
|
|
|
|
|
|
|
|
91
|
250
|
50
|
|
|
|
578
|
last LINE if $EVAL_ERROR; |
92
|
|
|
|
|
|
|
|
93
|
250
|
100
|
|
|
|
542
|
next LINE if !defined $current_line; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
124
|
100
|
|
|
|
209
|
if ( $args{merge_lines} ) { |
97
|
4
|
|
|
|
|
12
|
$all_lines->print($current_line); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
120
|
|
|
|
|
150
|
push @{$all_lines}, $current_line; |
|
120
|
|
|
|
|
242
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
18
|
50
|
|
|
|
51
|
if ($EVAL_ERROR) { |
105
|
0
|
|
|
|
|
0
|
croak "$EVAL_ERROR"; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
18
|
|
|
|
|
55
|
return $processors{'post'}->( $fh, $all_lines, \%args ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
######################################################################## |
112
|
|
|
|
|
|
|
sub _pre { |
113
|
|
|
|
|
|
|
######################################################################## |
114
|
18
|
|
|
18
|
|
40
|
my ( $file, $args ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
18
|
|
|
|
|
27
|
my $fh; |
117
|
|
|
|
|
|
|
|
118
|
18
|
50
|
|
|
|
69
|
if ( openhandle $file ) { |
119
|
18
|
|
|
|
|
37
|
$fh = $file; |
120
|
|
|
|
|
|
|
|
121
|
18
|
|
|
|
|
60
|
$args->{file} = ref $fh; # GLOB |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
else { |
124
|
0
|
0
|
|
|
|
0
|
open $fh, '<', $file ## no critic (RequireBriefOpen) |
125
|
|
|
|
|
|
|
or croak 'could not open ' . $file . $NL; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
0
|
$args->{'file'} = $file; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
18
|
|
|
|
|
37
|
$args->{'raw_count'} = 0; |
131
|
18
|
|
|
|
|
30
|
$args->{'skipped'} = 0; |
132
|
18
|
|
|
|
|
68
|
$args->{'start_time'} = time; |
133
|
|
|
|
|
|
|
|
134
|
18
|
100
|
|
|
|
81
|
my $lines = $args->{merge_lines} ? IO::Scalar->new : []; |
135
|
|
|
|
|
|
|
|
136
|
18
|
|
|
|
|
177
|
return ( $fh, $lines ); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
######################################################################## |
140
|
|
|
|
|
|
|
sub _next_line { |
141
|
|
|
|
|
|
|
######################################################################## |
142
|
52
|
|
|
52
|
|
97
|
my ( $fh, $all_lines, $args ) = @_; |
143
|
|
|
|
|
|
|
|
144
|
52
|
|
|
|
|
67
|
my $current_line; |
145
|
|
|
|
|
|
|
|
146
|
52
|
50
|
|
|
|
116
|
if ( openhandle $fh ) { |
147
|
52
|
100
|
|
|
|
283
|
if ( !eof $fh ) { |
148
|
44
|
50
|
|
|
|
121
|
defined( $current_line = readline $fh ) |
149
|
|
|
|
|
|
|
or croak "readline failed: $OS_ERROR\n"; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
52
|
|
|
|
|
142
|
return $current_line; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
######################################################################## |
157
|
|
|
|
|
|
|
sub _filter { |
158
|
|
|
|
|
|
|
######################################################################## |
159
|
126
|
|
|
126
|
|
298
|
my ( $fh, $all_lines, $args, $current_line ) = @_; |
160
|
|
|
|
|
|
|
|
161
|
126
|
50
|
|
|
|
259
|
if ( $args->{'chomp'} ) { |
162
|
126
|
|
|
|
|
224
|
chomp $current_line; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
126
|
100
|
100
|
|
|
317
|
if ( $args->{'trim'} && $args->{'trim'} =~ /(front|both)/xsm ) { |
166
|
12
|
|
|
|
|
28
|
$current_line =~ s/^\s+//xsm; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
126
|
100
|
100
|
|
|
286
|
if ( $args->{'trim'} && $args->{'trim'} =~ /(both|back)/xsm ) { |
170
|
12
|
|
|
|
|
26
|
$current_line =~ s/\s+$//xsm; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# skip? |
174
|
126
|
|
|
|
|
206
|
my $skip = $FALSE; |
175
|
|
|
|
|
|
|
|
176
|
126
|
100
|
100
|
|
|
410
|
if ( $args->{'skip_blank_lines'} || $args->{'skip_comments'} ) { |
177
|
|
|
|
|
|
|
|
178
|
12
|
100
|
100
|
|
|
35
|
if ( $args->{'skip_blank_lines'} && "$current_line" eq $EMPTY ) { |
179
|
1
|
|
|
|
|
4
|
$skip = $TRUE; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# if we're not chomping, then consider new line a blank line? |
183
|
12
|
50
|
33
|
|
|
24
|
if ( !$args->{chomp} && "$current_line" eq $NL ) { |
184
|
0
|
|
|
|
|
0
|
$skip = $TRUE; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
12
|
100
|
100
|
|
|
33
|
if ( $args->{'skip_comments'} && $current_line =~ /^\#/xsm ) { |
188
|
1
|
|
|
|
|
7
|
$skip = $TRUE; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
126
|
100
|
|
|
|
240
|
$args->{skipped} = $args->{skipped} + $skip ? 1 : 0; |
193
|
|
|
|
|
|
|
|
194
|
126
|
100
|
|
|
|
309
|
return $skip ? undef : $current_line; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
######################################################################## |
198
|
|
|
|
|
|
|
sub _process { |
199
|
|
|
|
|
|
|
######################################################################## |
200
|
115
|
|
|
115
|
|
286
|
my ( $fh, $all_lines, $args, $current_line ) = @_; |
201
|
|
|
|
|
|
|
|
202
|
115
|
|
|
|
|
214
|
return $current_line; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
######################################################################## |
206
|
|
|
|
|
|
|
sub _post { |
207
|
|
|
|
|
|
|
######################################################################## |
208
|
17
|
|
|
17
|
|
51
|
my ( $fh, $all_lines, $args ) = @_; |
209
|
|
|
|
|
|
|
|
210
|
17
|
|
|
|
|
39
|
$args->{end_time} = time; |
211
|
|
|
|
|
|
|
|
212
|
17
|
|
|
|
|
30
|
my $retval; |
213
|
|
|
|
|
|
|
|
214
|
17
|
100
|
|
|
|
37
|
if ( $args->{merge_lines} ) { |
215
|
1
|
|
|
|
|
2
|
$retval = ${ $all_lines->sref }; |
|
1
|
|
|
|
|
32
|
|
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
else { |
218
|
16
|
|
|
|
|
26
|
$retval = $all_lines; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
17
|
100
|
|
|
|
60
|
if ( !$args->{'keep_open'} ) { |
222
|
|
|
|
|
|
|
close $fh |
223
|
2
|
50
|
|
|
|
28
|
or croak 'could not close' . $args->{file} . $NL; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
17
|
|
|
|
|
30
|
return ( $retval, %{$args} ); |
|
17
|
|
|
|
|
191
|
|
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
######################################################################## |
230
|
|
|
|
|
|
|
sub post { ## no critic [Subroutines::RequireArgUnpacking] |
231
|
|
|
|
|
|
|
######################################################################## |
232
|
0
|
|
|
0
|
1
|
0
|
return $_[2]->{default_processors}->{post}->(@_); |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
######################################################################## |
236
|
|
|
|
|
|
|
sub filter { ## no critic [Subroutines::RequireArgUnpacking] |
237
|
|
|
|
|
|
|
######################################################################## |
238
|
0
|
|
|
0
|
1
|
0
|
return $_[2]->{default_processors}->{filter}->(@_); |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
######################################################################## |
242
|
|
|
|
|
|
|
sub pre { ## no critic [Subroutines::RequireArgUnpacking] |
243
|
|
|
|
|
|
|
######################################################################## |
244
|
10
|
|
|
10
|
1
|
146
|
return $_[1]->{default_processors}->{pre}->(@_); |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
######################################################################## |
248
|
|
|
|
|
|
|
sub process { ## no critic [Subroutines::RequireArgUnpacking] |
249
|
|
|
|
|
|
|
######################################################################## |
250
|
0
|
|
|
0
|
1
|
|
return $_[2]->{default_processors}->{process}->(@_); |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
######################################################################## |
254
|
|
|
|
|
|
|
sub next_line { ## no critic [Subroutines::RequireArgUnpacking] |
255
|
|
|
|
|
|
|
######################################################################## |
256
|
0
|
|
|
0
|
1
|
|
return $_[2]->{default_processors}->{next_line}->(@_); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
######################################################################## |
260
|
|
|
|
|
|
|
sub main { |
261
|
|
|
|
|
|
|
######################################################################## |
262
|
0
|
|
|
0
|
0
|
|
require IO::Scalar; |
263
|
0
|
|
|
|
|
|
require Data::Dumper; |
264
|
0
|
|
|
|
|
|
require JSON::PP; |
265
|
0
|
|
|
|
|
|
require Text::CSV_XS; |
266
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
JSON::PP->import('decode_json'); |
268
|
|
|
|
|
|
|
|
269
|
0
|
|
|
|
|
|
Data::Dumper->import('Dumper'); |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# +------------------+ |
272
|
|
|
|
|
|
|
# | READ A TEXT FILE | |
273
|
|
|
|
|
|
|
# +------------------+ |
274
|
|
|
|
|
|
|
|
275
|
0
|
|
|
|
|
|
my $buffer = <<'END_OF_TEXT'; |
276
|
|
|
|
|
|
|
line 1 |
277
|
|
|
|
|
|
|
line 2 |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
line 4 |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
line 5 |
282
|
|
|
|
|
|
|
END_OF_TEXT |
283
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
|
my $fh = IO::Scalar->new( \$buffer ); |
285
|
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
|
print Dumper( |
287
|
|
|
|
|
|
|
process_file( |
288
|
|
|
|
|
|
|
$fh, |
289
|
|
|
|
|
|
|
skip_blank_lines => $TRUE, |
290
|
|
|
|
|
|
|
chomp => $TRUE, |
291
|
|
|
|
|
|
|
trim => 'both' |
292
|
|
|
|
|
|
|
) |
293
|
|
|
|
|
|
|
); |
294
|
|
|
|
|
|
|
|
295
|
0
|
|
|
|
|
|
$fh = IO::Scalar->new( \$buffer ); |
296
|
|
|
|
|
|
|
print Dumper( |
297
|
|
|
|
|
|
|
process_file( |
298
|
|
|
|
|
|
|
$fh, |
299
|
|
|
|
|
|
|
post => sub { |
300
|
0
|
|
|
0
|
|
|
my @retval = post(@_); |
301
|
0
|
|
|
|
|
|
$retval[0] = join $EMPTY, @{ $_[1] }; |
|
0
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
|
return @retval; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
) |
305
|
0
|
|
|
|
|
|
); |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
# +------------------+ |
308
|
|
|
|
|
|
|
# | READ A JSON FILE | |
309
|
|
|
|
|
|
|
# +------------------+ |
310
|
|
|
|
|
|
|
|
311
|
0
|
|
|
|
|
|
my $json_text = <<'END_OF_TEXT'; |
312
|
|
|
|
|
|
|
{ |
313
|
|
|
|
|
|
|
"foo" : "bar", |
314
|
|
|
|
|
|
|
"baz" : "buz" |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
END_OF_TEXT |
318
|
|
|
|
|
|
|
|
319
|
0
|
|
|
|
|
|
$fh = IO::Scalar->new( \$json_text ); |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
print Dumper( |
322
|
|
|
|
|
|
|
process_file( |
323
|
|
|
|
|
|
|
$fh, |
324
|
|
|
|
|
|
|
chomp => 1, |
325
|
|
|
|
|
|
|
post => sub { |
326
|
0
|
|
|
0
|
|
|
post(@_); |
327
|
0
|
|
|
|
|
|
return decode_json( join $EMPTY, @{ $_[1] } ); |
|
0
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
) |
330
|
0
|
|
|
|
|
|
); |
331
|
|
|
|
|
|
|
|
332
|
0
|
|
|
|
|
|
$fh = IO::Scalar->new( \$json_text ); |
333
|
|
|
|
|
|
|
|
334
|
0
|
|
|
|
|
|
print Dumper( |
335
|
|
|
|
|
|
|
decode_json( process_file( $fh, merge_lines => 1, chomp => 1 ) ) ); |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# +-----------------+ |
338
|
|
|
|
|
|
|
# | READ A CSV FILE | |
339
|
|
|
|
|
|
|
# +-----------------+ |
340
|
|
|
|
|
|
|
|
341
|
0
|
|
|
|
|
|
my $csv_text = <<'END_OF_TEXT'; |
342
|
|
|
|
|
|
|
"id","first_name","last_name" |
343
|
|
|
|
|
|
|
0,"Rob","Lauer" |
344
|
|
|
|
|
|
|
END_OF_TEXT |
345
|
|
|
|
|
|
|
|
346
|
0
|
|
|
|
|
|
$fh = IO::Scalar->new( \$csv_text ); |
347
|
|
|
|
|
|
|
|
348
|
0
|
|
|
|
|
|
my $csv = Text::CSV_XS->new; |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
my ($csv_lines) = process_file( |
351
|
|
|
|
|
|
|
$fh, |
352
|
|
|
|
|
|
|
csv => $csv, |
353
|
|
|
|
|
|
|
chomp => 1, |
354
|
|
|
|
|
|
|
has_headers => 1, |
355
|
|
|
|
|
|
|
pre => sub { |
356
|
0
|
|
|
0
|
|
|
my ( $csv_fh, $args ) = @_; |
357
|
|
|
|
|
|
|
|
358
|
0
|
0
|
|
|
|
|
if ( $args->{'has_headers'} ) { |
359
|
0
|
|
|
|
|
|
my @column_names = $args->{csv}->getline($csv_fh); |
360
|
0
|
|
|
|
|
|
$args->{csv}->column_names(@column_names); |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
|
363
|
0
|
|
|
|
|
|
return ( pre( $fh, $args ) ); |
364
|
|
|
|
|
|
|
}, |
365
|
|
|
|
|
|
|
next_line => sub { |
366
|
0
|
|
|
0
|
|
|
my ( $csv_fh, $all_lines, $args ) = @_; |
367
|
0
|
|
|
|
|
|
my $ref = $args->{csv}->getline_hr($csv_fh); |
368
|
0
|
|
|
|
|
|
return $ref; |
369
|
|
|
|
|
|
|
} |
370
|
0
|
|
|
|
|
|
); |
371
|
|
|
|
|
|
|
|
372
|
0
|
|
|
|
|
|
print Dumper($csv_lines); |
373
|
|
|
|
|
|
|
|
374
|
0
|
|
|
|
|
|
exit 0; |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
1; |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
__END__ |