Created
September 22, 2012 17:53
-
-
Save hatorikibble/3767138 to your computer and use it in GitHub Desktop.
Beispiel fuer eine SQL-Abfrage mit DBD::CSV auf eine CSV-Datei
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use DBD::CSV; | |
use Data::Dumper; | |
# DBD::CSV normiert die Spaltennamen | |
my @programme = | |
qw (quellen_manager_in_microsoft_word_ endnote refworks jabref zotero bibtex___biblatex citavi citeulike mendeley); | |
my $dbh = undef; | |
my $sth = undef; | |
my $query = undef; | |
$dbh = DBI->connect( | |
"dbi:CSV:", | |
undef, undef, | |
{ | |
f_dir => ".", # im aktl Verzeichnis nach CSV Dateien schauen | |
csv_eol => "\r\n", # Windows | |
csv_sep_char => ";", | |
csv_quote_char => '"', | |
f_encoding => "iso-8859-1", | |
} | |
); | |
foreach my $prog (@programme) { | |
# "Habe ... ausprobiert / ..damit geschrieben" -> schon mal verwendet | |
$query = <<"EOS"; | |
SELECT count(*) as anzahl FROM dbd.csv where $prog LIKE 'Habe\%'"; | |
EOS | |
$sth = $dbh->prepare($query); | |
$sth->execute(); | |
while ( my $row = $sth->fetchrow_hashref ) { | |
print "$prog: $row->{anzahl}\n"; | |
} | |
$sth->finish(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment