Please use <code> </code> tags around your code so that the line breaks are preserved. The eval{} goes around the dbi method code! Not around the subroutine! Anyway this is how to use eval... The connect asks to use RaiseError =>1 and I'm not sure that's in effect if the connect fails so I think the extra die is just fine- just in case. If the connect succeeds, the "do" happens next.
sub OpenSybaseConnection
{
my ($srv, $user, $pwd, $db) = @_;
my $dbh;
$FH1=$_4; #????????????????????????????
eval
{
$dbh=DBI->connect( "dbi:Sybase:server=$srv", $user, $pwd,
{RaiseError =>1, PrintError =>1} )
or die "Extra death $DBI::errstr";
$dbh->do("use $db");
};
if($@) # true if the eval failed (die'd at some point)
{
@proc_error=$@ ;
print "inside if\n";
print "Hi:$@";
print "\nIn Common: @proc_error: HELP";
}
else # this is the "no error" case
{
$common::conn_hdl = $dbh;
print $FH1 "\n\nConnected to Server:$srv, Database:$db\n";
}
return;
}
|