Perlnoob17 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am a college student working on a Perl assignment. My goal is to count the number of files inside of a UDB file, and then later use this variable for another part of the assignment. I'm new to the syntax, and I'm not lazy by any means, but I'd like some insight on how to go about doing this as I start.

A UDB file is a database file for a project. From my limited understanding, these project files contain the many files within which are all referenced between eachother when using OOP. So, my question is if this is possible to pass a database file into a PERL script and have it somehow increment a variable for each file within.

Thank you.

Replies are listed 'Best First'.
Re: Database files and PERL
by huck (Prior) on Jun 01, 2017 at 02:07 UTC
Re: Database files and PERL
by anonymized user 468275 (Curate) on Jun 01, 2017 at 21:19 UTC
    First you need to be acquainted with DBI (search for it on CPAN). For UDB it is reasonable to equate the term file with table. So you want to count the tables in the database. The SQL command LIST TABLES will be understood by DB2, so you just have to prepare and execute the LIST TABLES statement and fetch the results into an array reference. If the array reference is saved to say $fred, then the perl expression "scalar @$fred" will return a count of the tables in the UDB. This is an overview, of course the real exercise is to understand a whole bunch of methods in the DBI class, documented in CPAN.

    One world, one people

A reply falls below the community's threshold of quality. You may see it by logging in.