Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How to give a database as an input in a perl script?

by amature (Initiate)
on May 31, 2012 at 04:11 UTC ( #973423=perlquestion: print w/ replies, xml ) Need Help??
amature has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks!

I have written a perl script which reads a whole directory and takes all the files in a directory as input. Now instead of giving a directory as a input, i want to give a database as a input and it must read all the tables in the database like reading the files in a directory.

How can i do this please suggest me a way or an idea. I would be very grateful for the same.

Thanks ahead of time!

Comment on How to give a database as an input in a perl script?
Re: How to give a database as an input in a perl script?
by GrandFather (Cardinal) on May 31, 2012 at 04:28 UTC

    Something like:

    use strict; use warnings; use DBI; my $dbh = DBI->connect(...); my $tables = $dbh->selectall_arrayref('show tables'); print "$_->[0]\n" for @$tables;
    True laziness is hard work

      Instead of the (somewhat) database specific show tables, I prefer to offload that knowledge to the database driver. DBI has lots of Catalog Methods that return structured data about the database itself. Of course, some of it is implemented by issuing a show tables command.

      Generic version:
      use strict; use warnings; use DBI; my $dbh = DBI->connect(...); my @tables = $dbh->tables(undef, undef, undef, 'TABLE'); print "$_\n" for @tables;
      The tables method should work for all databases supported by DBI. Sending a show tables query is MySQL-specific - I know it doesn't work with SQLite databases and, from long-gone memory, I'm pretty sure PostgreSQL wouldn't like it either. Any other database engine, I can only say "seems unlikely".

      @GrandFather Thanks now i have got some kind of idea

Re: How to give a database as an input in a perl script?
by choroba (Abbot) on May 31, 2012 at 07:33 UTC
    Crossposted at StackOverflow. It is considered polite to inform about crossposting so people not visiting both sites do not waste their time on a problem already solved at the alien site.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://973423]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-07-31 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (245 votes), past polls