my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
PrintError => 1,
RaiseError => 1,
f_dir => ".",
f_ext => ".csv/r",
f_schema => undef,
csv_null => 1,
csv_auto_diag => 1,
});
Using f_ext like that enables you to mix code (.pl-files) and data (.csv-files) in a single directory, and still be able to only see the tables (without the .csv extension).
merijn@tux:~> cat xx.pl
#!/pro/bin/perl
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
RaiseError => 1,
PrintError => 1,
f_dir => ".",
f_ext => ".csv/r",
f_schema => undef,
csv_null => 1,
csv_auto_diag => 1,
});
my $sth = $dbh->prepare ("select b, e from xx order by d, f");
$sth->execute;
while (my @row = $sth->fetchrow_array) {
print "@row\n";
}
merijn@tux:~> cat xx.csv
a,b,c,d,e,f
1,2,3,4,5,6
1,3,4,5,3,4
2,5,2,5,2,5
2,4,1,5,8,1
3,5,2,8,1,9
4,5,6,7,8,9
5,1,4,2,5,3
6,2,5,7,1,8
merijn@tux:~> ls -d x*
x0 x1 xloadall xx xx.csv xx.pl
merijn@tux:~> perl xx.pl
2 5
3 3
5 2
4 8
5 1
5 8
1 5
2 1
merijn@tux:~>
Enjoy, Have FUN! H.Merijn
|