Perl Program, CGI, DBI - Access Database (.MDB) Example

Active State Perl 5.8 is really a powerful language which can run on either Unix or Windows platforms. Perl has several Common Gateway Interface (CGI) and Database Interface (DBI) modules that can be utilized rather easily, to create web based applications. It is really good at parsing data and storing the result sets in various Database platforms, XML Documents and ASCII text flat files. You can download free source code compilers and utilities from Active Sate.

I recently wrote a Perl program that stored digital images and information pertaining to those images in a SQL Server 2003 and Microsoft Access Database. The purpose of the application was to parse and store *.jpg images, file names, path settings, byte sizes and last updated dates. I used a series of command batch files to create driver list text files for parsing directory structures and the file names. The following application example used just DOS commands in maninpulating the input and output data.

In addition to Computer Programming, I also like to play the guitar, read and write music, learn new songs and transcribe what I've learned for my family and friends. I have written other Perl programs, Java Script, Visual Basic, .NET and XML XSLT applications for maintaining all of these different types of media. The following Perl program was written to parse guitar tab *.txt files from specific directories and store them in a Microsoft Access Database.

Step 1: Determine a specific directory or folder to output the contents list into a *.txt file for parsing.

Notice below, that I created a C:\GuitarTabs\Danzig directory and created four tab *.txt files containing guitar parts to some Danzig songs.

I did a DOS dir command out to a dir_tab_list.txt file. This file was ultimately used as input in the Perl program

DOS Commands dir and copy to create dir_tab_list.txt file containing C:\GuitarTabs\Danzig tab *.txt song filesGlenn Danzig Band Wrote These Heavy Songs

Step 2: Moved the Input file to the target directory.

Notice above, that I did a DOS copy command of the dir_tab_list.txt file to the C:\Perl\Access_MDB directory. I created this directory specifically for this example. This directory also contains the Perl program and the Microsoft Access Database guitar_tabs.MDB.

Step 3: Created the Microsoft Access Database.

I created the Microsoft Access guitar_tabs.MDB and table guitar_tabs in the directory C:\Perl\Access_MDB directory. You can also use MySQL, Informix, DB2, Oracle and Sybase Database platforms with Perl programs.

Microsoft Access Database guitar_tabs.mdb and guitar_tabs table with layout

Step 4: Created Microsoft ODBC System DSN.

I created the Microsoft Access Database ODBC DSN for C:\Perl\Access_MDB\guitar_tabs.MDB. This will allow the Perl program to read and write to the database.

Microsoft ODBC DSN for guitar_tabs.mdb

Step 5: Wrote Perl program.

I wrote the Perl program to read the dir_tab_list.txt file and save the guitar tab *.txt file names and dates in the guitar_tabs.MDB.

Perl program sec 1
Perl program sec 2
Perl program sec 3

Step 6: Run Perl program.

Run Perl program to read the dir_tab_list.txt file and save the guitar tab *.txt file names and dates to the guitar_tabs.MDB.

Display of dir_tab_list.txt contents and Running of application with printed file names actually parsed

Step 7: Verify Perl program Results.

Verify Perl program successfully read the dir_tab_list.txt file and saved the guitar tab *.txt file names and dates to the guitar_tabs.MDB.

Results of in database

Steven C. Howes and Howes-IT-Going are NOT Responsible for Usage or Reproduction of ANY Copyrighted Glenn Danzig Music Titles.
This Perl Application, Microsoft Access Database and ODBC DSN were for Educational and Discussion Purposes ONLY. Terms of use.

Go Back to:

This Webpage and Contents Created by Steven C. Howes © Howes-IT-Going 2003-2012 All rights reserved.