#! /usr/bin/perl -w use open ":utf8"; use strict; use DBI; BEGIN { binmode STDOUT, ":utf8"; } my $DB = DBI->connect("dbi:Pg:host=roadstar", "", "", { AutoCommit => 0, RaiseError => 1 }); my $st = $DB->prepare ("SELECT title, ndisc, path FROM old_dvd ORDER BY title"); $st->execute; my $st1 = $DB->prepare ("INSERT INTO dvd (title, disc, path) VALUES (?, ?, ?)"); while (my @r = $st->fetchrow_array) { my ($title, $ndisc, $path) = @r; print ";; $title [$ndisc]\n"; for (my $i = 0; $i < $ndisc; $i++) { $st1->execute($title, $i, $path); } } $DB->commit; $DB->disconnect;