1

Is there a way to check if DB exists using perl ? Its a quick and easy one. but im still getting used to perl and DB

2
  • 1
    stackoverflow.com/questions/838978/… Commented Jan 18, 2013 at 20:22
  • 1
    The alternative question SO 838978 does not cover Perl at all; this question is specifically about Perl. This question is not a duplicate of that one. Commented Jan 18, 2013 at 21:01

1 Answer 1

4

The DBI module is a popular way access and manipulate databases in perl. Here is a short example of usage of DBI which tests a connection:

use DBI;

$user = 'donny';
$pw = 'ppp';
$dsn = 'basetest';
$dbh = DBI->connect($dsn, $user, $pw) or die "Unable to connect: $DBI::errstr\n";

The last line could also be something more like:

$dbh = DBI->connect('dbi:Oracle:',$user.'@'.$password,$dbconnectstring);

Or something similar - just edit the first parameter as makes sense.

As you can see - you'll get unable to connect if the DB can't be found.

Here is the documentation relevant to DBI: http://dbi.perl.org/docs/

Sidenote: Also, note you can access sqlplus - or any command line - within a perl script. Just use backticks. It may be worth it to check that way, if you have the tools available on the machine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.