#!/usr/bin/perl use strict; use warnings; use DBI; # Database Definition my $dbh = &DB_OPEN('myDatabase','localhost','3306','user','password'); sub DB_OPEN { my ($db_name,$host_name,$port,$db_user,$db_pass,) = @_; $database = "DBI:mysql:$db_name:$host_name:$port"; $dbh = DBI->connect($database,$db_user,$db_pass); } # end-sub # Do a typical select that retrieves many results... my %DataHash; my $sth = $dbh->prepare(" select ID, Data from table_name where Data=\"value\" "); $sth->execute; while ( my ( $ID, $Data) = $sth->fetchrow ) { $CountryDisplay{$ID} = "$Data"; } # end-while $sth->finish; # Do the updating... foreach (keys (%Data)) { $dbh->do(" update new_table set newData=\"$Data{$_}\" where newID=$_ "); } # end-foreach # Disconnect $dbh->disconnect; exit;