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.


prasen120998Asked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.