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

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

Replies are listed 'Best First'.
Re^2: How to give a database as an input in a perl script?
by Corion (Patriarch) on May 31, 2012 at 07:41 UTC

    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.

Re^2: How to give a database as an input in a perl script?
by dsheroh (Monsignor) on May 31, 2012 at 09:38 UTC
    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".
Re^2: How to give a database as an input in a perl script?
by amature (Initiate) on May 31, 2012 at 17:19 UTC

    @GrandFather Thanks now i have got some kind of idea