in reply to Getting null value from last_insert_id()

You always should check for errors, maybe the insertion just doesn't happen for some reason and that's why there is no last_insert_id.

Depending on how you open/manage your DB connection, you might want either to raise an exception on error that you would trap within an eval {}; block, or explicitely check the result/error code.

Have a look into DBD::mysql, maybe it helps a bit.

Depending on the chosen way to deal with errors, your code probably should look like
my $tmp_query="insert into <TableName> values('','');"; eval { $sth = $dbh->prepare($tmp_query); $sth->execute(); $sth->finish(); }; if ($@) { # error... }
or
$sth = $dbh->prepare($tmp_query); if (!$sth) { die "Error:" . $dbh->errstr . "\n"; } if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; } ...