Muchas Gracias!! Esteban, entonces la cuestión sería asi:
archivo auto.pm:
Código:
#!/usr/bin/perl -w
package AUTO;
use strict;
use DBI;
my $db_user = "aaa";
my $db_pass = "bbb";
my $host_name = "10.10.10.10:3306";
my $db_name = "base;
# vars
my $q_string = "DBI:mysql:host=$host_name;database=$db_name";
sub connect{
return (DBI->connect ($q_string, $db_user, $db_pass,
{PrintError => 0, RaiseError => 1}));
}
1
y el otro llamado script.pl:
Código:
use AUTO
my($dbh,$sth);
$dbh = AUTO->connect();
$sth = $dbh->prepare('select max(id_tabla)+1 num from tabla') or die("Couldn't prepare statement: " . $dbh->errstr);
$sth->execute() or die("Couldn't execute statement: " . $sth->errstr);
my $maxnum = $sth->fetchrow_array();
$sth->finish;
$sth1-> $dbh->prepare('insert into tabla (id_tabla) values (?)');
$sth1->execute($maxnum) or die("Couldn't execute statement: " . $sth->errstr);
$dbh->disconnect;
exit;