How to skip database errors in perl

Posted on 2007-10-12
Last Modified: 2012-05-05
I've a perl script, in which I need to make multiple database connections in each sub function

DBI->connect(database1, user, passwd);

DBI->connect(database2, user2, passwd2);

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

sub subFn2()
  my $sel2= DBI->prepare("Select...");
 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.

Question by:prasen120998
    LVL 84

    Accepted Solution

    eval { code to make nonfatal };  warn $@ if $@;

    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now