Link to home
Start Free TrialLog in
Avatar of prasen120998
prasen120998

asked on

How to skip database errors in perl

I've a perl script, in which I need to make multiple database connections in each sub function

example,
main()
{
DBI->connect(database1, user, passwd);
&subFn1();
DBI->disconnect;

DBI->connect(database2, user2, passwd2);
&subFn2();
DBI->disconnect;
:
:
}

sub subFn1()
{
  my $sel1= DBI->prepare("Select...");
  $sel1->execute();
 my $var1 = $sel1->fetchrow();
}

sub subFn2()
{
  my $sel2= DBI->prepare("Select...");
  $sel2->execute();
 my $var2 = $sel2->fetchrow();
}

Now, if there is any error or one of the database is down, the program shouldn't exit with error, rather it should continue to the next database connections.
Similarly, if there is any inside the subroutines, it shouldn't die, rather it should continue till the end of the program

How do I achieve this.


ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prasen120998
prasen120998

ASKER

ozo, could you pls elaborate a little bit more, based on the above example