Created
March 11, 2010 20:11
-
-
Save mxey/329593 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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