• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

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.


0
prasen120998
Asked:
prasen120998
1 Solution
 
ozoCommented:
eval { code to make nonfatal };  warn $@ if $@;
0
 
prasen120998Author Commented:
ozo, could you pls elaborate a little bit more, based on the above example
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now