tab-to-table.cgi

by Mike VanHorn
( mvanhorn@gemair.com )

A program written in the Perl language to display tab-delimited text
files as HTML tables.

System Requirements

A web server with Perl installed

Installation Notes

I have installed and tested this script on UNIX and Macintosh web servers,
and it works on both of them. Testing on a Windows NT server has not
yet been completed, but it should work there, too, I just don't have
Windows NT-specific installation instructions yet.

Exporting the Database

The first thing you have to do to use this script, is go into Works and
save your database file as a tab-delimited text file. For details on
how to do this, see your Works manual.

Installing the Script

On UNIX servers, you need to check that the path to Perl at the top of the
script is correct ( see fig 1). This varies from system to system, so if
you're not sure what this should be, check with your system administrator.

#!/usr/bin/perl
#
# tab-to-table
#
# This script takes a tab-delimited text file, and turns it
# into an HTML <TABLE>
#
# Mike VanHorn, 22 Oct 1998
#
Figure 1

This is the very top of the tab-to-table.cgi Perl Script. If you are
using a UNIX server, you need to make sure that the path to the Perl
interpreter ( /usr/bin/perl in this example ) is correct. If you're not
sure, check with your sys admin.

On other systems ( e.g. Macintosh ), the path to Perl at the top of the
script isn't important, you just have to make sure you have the extension
of the script correct. Usually, the proper extension is .pl or .cgi,
but check your documentation or your sys admin if you're not sure.

You also need to change the value of the directory_thing variable (see fig
2 ). The directory_thing variable specifies what the directory delimiter
is on the operating system you are using. As noted in the script, the
value of this should be "./" ( dot slash ) on a UNIX system and ":"
( colon ) on a Macintosh system.


# $directory_thing is used for portability between Mac and UNIX 
# Perl. If you're running this script under UNIX, $directory_thing 
# should be "./". On a Mac, it should be ":".
$directory_thing = "./";
Figure 2

Edit the script so that directory thing is appropriate for your
operating system.

Finally, you have to put the script in a place where it can be executed
by the web server. This is often in a directory called cgi-bin, but the
location varies from system to system. If you are the administrator of
the server, consult you documentation for where to put the script. If
you don't have the ability to install cgi scripts yourself, you may need
to have an administrator-type person install the script for you.

Note: the location of the script and the location of the tab-delimited
text file to be displayed doesn't have to be the same ( see below ). In
other word, you can have the script installed in a system-wide directory,
and have multiple users use the script with their database files in
their own directories.

Make the dat File

For each tab-delimited file you are putting on the web, you will have
one dat file. The dat file is the configuration file that you give to
the script as an argument, and that the script uses to determine which
files to use when displaying the tab-delimited file.

The dat file looks something like this: 

input_file,/home/smith/www/sample.tab
body_top,/home/smith/www/sample.top
body_bottom,/home/smith/www/sample.bot

First an explanation of the things on the left side of the comma: 

input_file is the name of the tab-delimited file you want the script
to use.

body_top is the name of the file that contains all of the HTML code you
want to appear before the table.

body_bottom is the name of the file that contains all of the HTML code
you want to appear after the table.

On the right side of the commas are full paths to the files you want to
use. These are NOT the URLs to the files; these are the paths that the
operating system of the server uses ( the actual paths, you might say ).

The dat file must be placed in the same directory as the tab-to-table.cgi
script. So, if you had to have an administrator type person put the
tab-to-table.cgi program into a system-wide cgi-bin directory, you'll
have to have her put the dat file into the same directory.

Executing the Script

Now, to use the script, you make a call to it from your browser, either
directly or as a link in a page, of the form

http://www.server.com/~smith/cgi-bin/tab-to-table.cgi?dat_file=nameofdatfile

where nameofdatfile is the name of the dat file you made from above. 

Since the call to the script specifies which dat file to use, and the
dat files specifies which tab-delimited file to use, any user on the
system can use the script for any number of tab-delimited files, no
matter where that person's files are.

For an example of the script in action, go to
http://www.gemair.com/%7Emvanhorn/cgi-bin/tab-to-table.cgi?dat_file=urls.dat.

For More Information

If something in this document wasn't clear, or if you have questions or
comments or suggestions regarding the tab-to-table script, send email
to mvanhorn@gemair.com.

