in reply to my and its use

Your problem is in the "|| die "Cannot connect!: $!\n$dbh->errstr";".

"my $var" causes the variable to come into existance after the line containing "my" is executed. Since the "|| die" part is part of the same line, $dbh isn't yet defined.

--
Ryan Koppenhaver, Aspiring Perl Hacker
"I ask for so little. Just fear me, love me, do as I say and I will be your slave."