line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
######################################################### |
2
|
|
|
|
|
|
|
package AnyData::Format::Tab; |
3
|
|
|
|
|
|
|
######################################################### |
4
|
|
|
|
|
|
|
# copyright (c) 2000, Jeff Zucker |
5
|
|
|
|
|
|
|
# all rights reserved |
6
|
|
|
|
|
|
|
######################################################### |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
AnyData::Format::Tab - tiedhash & DBI/SQL access to Tab delimited files |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use AnyData; |
15
|
|
|
|
|
|
|
my $table = adHash( 'Tab', $filename,'r',$flags ); |
16
|
|
|
|
|
|
|
while (my $row = each %$table) { |
17
|
|
|
|
|
|
|
print $row->{name},"\n" if $row->{country} =~ /us|mx|ca/; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
# ... other tied hash operations |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
OR |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use DBI |
24
|
|
|
|
|
|
|
my $dbh = DBI->connect('dbi:AnyData:'); |
25
|
|
|
|
|
|
|
$dbh->func('table1','Tab', $filename,$flags,'ad_catalog'); |
26
|
|
|
|
|
|
|
my $hits = $dbh->selectall_arrayref( qq{ |
27
|
|
|
|
|
|
|
SELECT name FROM table1 WHERE country = 'us' |
28
|
|
|
|
|
|
|
}); |
29
|
|
|
|
|
|
|
# ... other DBI/SQL operations |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This is a plug-in format parser for the AnyData and DBD::AnyData modules. It will read column names from the first row of the file, or accept names passed by the user. In addition to column names, the user may set other options as follows: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
col_names : a tab separated list of column names |
36
|
|
|
|
|
|
|
eol : the end of record mark, \n by default |
37
|
|
|
|
|
|
|
quote_char : the character used to quote fields " by default |
38
|
|
|
|
|
|
|
escape_char : the character used to escape the quote char, " by default |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
If you are using this with DBD::AnyData, put ad_ in front of the flags, e.g. |
41
|
|
|
|
|
|
|
ad_eol. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Please refer to the documentation for AnyData.pm and DBD::AnyData.pm |
44
|
|
|
|
|
|
|
for further details. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 AUTHOR & COPYRIGHT |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
copyright 2000, Jeff Zucker |
49
|
|
|
|
|
|
|
all rights reserved |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
54
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
55
|
1
|
|
|
1
|
|
8
|
use AnyData::Format::CSV; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
56
|
1
|
|
|
1
|
|
5
|
use vars qw( @ISA $VERSION ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
173
|
|
57
|
|
|
|
|
|
|
@AnyData::Format::Tab::ISA = qw( AnyData::Format::CSV ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$VERSION = '0.05'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub new { |
62
|
1
|
|
|
1
|
0
|
2
|
my $class = shift; |
63
|
1
|
|
50
|
|
|
3
|
my $flags = shift || {}; |
64
|
1
|
|
50
|
|
|
5
|
$flags->{field_sep} ||= qq(\t); |
65
|
1
|
|
|
|
|
6
|
my $self = AnyData::Format::CSV::->new( |
66
|
|
|
|
|
|
|
$flags |
67
|
|
|
|
|
|
|
); |
68
|
1
|
|
|
|
|
5
|
return bless $self, $class; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
1; |