Skip to content

Instantly share code, notes, and snippets.

@mxey
Created March 11, 2010 20:11
Show Gist options
  • Select an option

  • Save mxey/329593 to your computer and use it in GitHub Desktop.

Select an option

Save mxey/329593 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use autodie;
use DBI;
use Encode;
use IO::Handle;
use SQL::Abstract;
if (@ARGV != 1) {
STDERR->say("Usage: $0 CONFIGFILE");
exit 1;
}
my $conf = do $ARGV[0];
my $dbh = DBI->connect(@{ $conf->{database} }, { RaiseError => 1 });
my $sql = SQL::Abstract->new();
$dbh->begin_work;
LINE: while (my $line = <STDIN>) {
foreach (@{ $conf->{patterns} }) {
my($p, $d) = @{$_};
if ($line =~ $p) {
my($stmt, @bind) = $sql->insert($d, \%+);
my $sth = $dbh->prepare_cached($stmt);
$sth->execute(@bind);
next LINE;
}
}
}
$dbh->commit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment