The easy (and a bit slower) way is to do a loop of update statements:
use strict; use DBI; my @left_column = do { open my $fh, "<", 'data/left_file.txt' }; my @right_column = do { open my $fh, "<", 'data/right_file.txt' }; chomp @left_column; chomp @right_column; my $dbh = DBI->connect(...); my $sth = $dbh->prepare(<<SQL); UPDATE wordtable SET right_column = ? WHERE left_column = ? SQL; for my $index (0..$#left_column) { $sth->execute($right_column, $left_column); };
You will want to read about the placeholders in the DBI documentation.
A different approach might be to construct one huge CASE statement, but you might run against the query text size limits of your database:
my $statement = 'UPDATE wordtable SET right_column = CASE '; $statement .= join "\n", map { "WHEN left_column = '$left_column[_]' T +HEN '$right_column[$_]'" } 0..$#left_column; $statement .= "END;"; print $statement;
In reply to Re^3: change data in the mysql through DBI
by Corion
in thread change data in the mysql through DBI
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |