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
-
1stackoverflow.com/questions/838978/…PleaseStand– PleaseStand2013-01-18 20:22:08 +00:00Commented Jan 18, 2013 at 20:22
-
1The 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.Jonathan Leffler– Jonathan Leffler2013-01-18 21:01:40 +00:00Commented Jan 18, 2013 at 21:01
1 Answer
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.