line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::File::AnyData::MultiRecord_CSV; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
65569
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
71
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
49
|
|
5
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
176
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN{ |
8
|
2
|
|
|
2
|
|
1644
|
require Parse::CSV; |
9
|
2
|
|
|
|
|
70296
|
require Tie::File::AnyData; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub TIEARRAY |
15
|
|
|
|
|
|
|
{ |
16
|
3
|
|
|
3
|
|
3353
|
my ($pack,$file,%opts) = @_; |
17
|
3
|
|
50
|
|
|
38
|
my $field_sep = $opts{'field_sep'} || "\t"; |
18
|
3
|
|
100
|
|
|
16
|
my $key = $opts{'key'} || 0; |
19
|
3
|
|
50
|
|
|
18
|
my $recsep = $opts{'recsep'} || "\n"; |
20
|
3
|
|
|
|
|
6
|
delete $opts{'field_sep'}; |
21
|
3
|
|
|
|
|
5
|
delete $opts{'key'}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $coderef = sub { |
24
|
2
|
|
|
2
|
|
48658
|
use Parse::CSV; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
453
|
|
25
|
641
|
|
|
641
|
|
112183
|
my ($fh) = @_; |
26
|
641
|
100
|
|
|
|
5418
|
return undef if (eof $fh); |
27
|
434
|
|
|
|
|
1334
|
my $csv_parser = Parse::CSV->new ( |
28
|
|
|
|
|
|
|
handle => $fh, |
29
|
|
|
|
|
|
|
sep_char => $field_sep |
30
|
|
|
|
|
|
|
); |
31
|
434
|
|
|
|
|
56972
|
my $arref = $csv_parser->fetch; |
32
|
434
|
|
|
|
|
21761
|
my $rec = join ("$field_sep",@$arref).$recsep; |
33
|
434
|
|
|
|
|
476
|
my $rec_key = ${$arref}[$key]; |
|
434
|
|
|
|
|
792
|
|
34
|
434
|
|
|
|
|
536
|
my $pos = tell($fh); |
35
|
434
|
|
|
|
|
987
|
while (my $arref = $csv_parser->fetch){ |
36
|
2877
|
100
|
|
|
|
102412
|
if (${$arref}[$key] eq $rec_key){ |
|
2877
|
|
|
|
|
5317
|
|
37
|
2447
|
|
|
|
|
5496
|
$rec .= join "$field_sep",(@$arref); |
38
|
2447
|
|
|
|
|
2349
|
$rec .= $recsep; |
39
|
2447
|
|
|
|
|
2672
|
$pos = tell($fh); |
40
|
2447
|
100
|
|
|
|
10612
|
return $rec if eof($fh); |
41
|
|
|
|
|
|
|
} else { |
42
|
430
|
|
|
|
|
5014
|
seek $fh,$pos,0; |
43
|
430
|
|
|
|
|
4170
|
return $rec; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
3
|
|
|
|
|
23
|
}; |
47
|
|
|
|
|
|
|
|
48
|
3
|
50
|
|
|
|
11
|
carp "Overriding code ref" if (defined $opts{'code'}); |
49
|
3
|
|
|
|
|
13
|
local $/="\n"; |
50
|
3
|
|
|
|
|
17
|
Tie::File::AnyData::TIEARRAY ( |
51
|
|
|
|
|
|
|
'Tie::File::AnyData', |
52
|
|
|
|
|
|
|
$file, |
53
|
|
|
|
|
|
|
%opts, |
54
|
|
|
|
|
|
|
code => $coderef |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |