Skip to content

Instantly share code, notes, and snippets.

@hatorikibble
Created September 22, 2012 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatorikibble/3767138 to your computer and use it in GitHub Desktop.
Save hatorikibble/3767138 to your computer and use it in GitHub Desktop.
Beispiel fuer eine SQL-Abfrage mit DBD::CSV auf eine CSV-Datei
#!/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