Danke. Nach deiner Anregung mit den col_names hab ich nochmal genau die Doku gelesen jetzt gehts.
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
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
# Declare variables
my $db = '/home/format_c/tmp/csvdb';
my $prefix = '+49';
# Makes a Datebase Handler
my $dbh = DBI->connect("DBI:CSV:f_dir=$db") or die DBI::errstr;
$dbh->{csv_tables}->{phonebook} = { file => 'Phonebook_SM.csv',
#col_names => ["id", "nummer", "name"],
eol => "\n",
sep_char => ",",
quote_char => '"',
escape_cahar => '\\',
};
my $sql = qq|
SELECT * FROM phonebook
|;
my $sth = $dbh->prepare( $sql ) or die $dbh->errstr;
$sth->execute() or die $dbh->errstr;
while (my @row = $sth->fetchrow_array()) {
printf "%s : %s : %s \n", @row;
}
$sth->finish();
$dbh->disconnect();
exit;
Musste nur das Format der CSV-Datei genau definieren.
Ach ja zu deiner Verwunderung vorhin hab ich auch was gefunden:
perldoc DBD::CSV
skip_first_row
By default DBD::CSV assumes that col-
umn names are stored in the first row
of the CSV file. If this is not the
case, you can supply an array ref of
table names with the col_names
attribute. In that case the attribute
skip_first_row will be set to FALSE.
If you supply an empty array ref, the
driver will read the first row for
you, count the number of columns and
create column names like "col0",
"col1", ...
Gruß Alex\n\n
<!--EDIT|format_c|1079891801-->