8 Einträge, 1 Seite |
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
#!/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;csv_sep_char=,;") or die DBI::errstr; $dbh->{csv_tables}->{phonebook} = { file => 'Phonebook_SM.csv' }; 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()) { print join "\t",@row . "\n"; } $sth->finish(); $dbh->disconnect(); exit;
1
2
format_c@linux:~/Develop/Perl/Update Phonebook> perl set_germ_prefix.pl
format_c@linux:~/Develop/Perl/Update Phonebook>
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
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
# Declare variables
my $db = 'C:/Perlen/csv';
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 => 'test.csv' };
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()) {
print join "\t", @row;
print "\n";
}
$sth->finish();
$dbh->disconnect();
exit;
1
2
3
4
ID, Nummer, Vorname, Nachname
1,"0000000000000","Christine","Nachname"
2,"+49000000000000","PS","Bernhardt"
3,"+496985725","Irgendwer","Nachname"
1
2
3
4
5
$dbh->{csv_tables}->{phonebook} =
{
'file' => 'test.csv',
'col_names' => ["ID", "Nummer", "Vorname", "Nachname"],
};
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 = 'C:/Perlen/csv';
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' => 'test.csv',
'col_names' => ["ID", "Nummer", "Vorname", "Nachname"],
};
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()) {
print join "\t", @row;
print "\n";
}
$sth->finish();
$dbh->disconnect();
exit;
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;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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", ...
8 Einträge, 1 Seite |