in reply to Trouble with syntax with SELECT

First, I don't think MySQL lets you do a "SELECT * FROM A INTO B", though you can do:
INSERT INTO A (col1,col2,col3) SELECT fld1,fld2,fld3 FROM B;
Also, you only need one database connection to run both those queries since they both act on the same database. And, I would use $row[0] a bit differently,
my @pats = (); my $dbh = DBI->connect("DBI:mysql:database=proyecto;host=localhost", "root", "xyz123", {'RaiseError' => 1} ); my $sth = $dbh->prepare("SELECT DISTINCT PAT FROM patentes"); $sth->execute(); while (my @row = $sth->fetchrow_array) { push @pats, $row[0]; } foreach (@pats) { # TODO: CREATE TABLE NAMED $_ HERE ? $dbh->do("INSERT INTO $_(col1,col2,col3) SELECT fld1,fld2,fld3 FR +OM patente WHERE pat = $_"); }
However, from your post, it sounds like you'll also need to run a CREATE statement for each table in @pats, unless they already exist.

---
echo S 1 [ Y V U | perl -ane 'print reverse map { $_ = chr(ord($_)-1) } @F;'
Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.