My company's web server runs IIS and Cold Fusion to connect to an Oracle
database.  Our customers can get read-only access to information about
their inventory through this system.  The problem is we run our business
on VMS in RMS files.  There can be a significant delay between an update
being made in RMS and that change being seen in Oracle.  Also, since the
web applications don't have direct access to the live data, implementing
anything but inquiry routines would be next to impossible.

I convinced my boss that we should attempt to convert the site to a VMS
based web server so we could access the RMS files directly.  I've been
using perl for quite some time and decided to install the VMS version. 
Through this list I found out about the OSU DECthreads webserver and got
it installed.  I tried some perl modules I had previously written for
linux and NT and they worked without a hitch (even Oracle access!).

So, I started working on creating a new company web site. 
VMS::IndexedFile provides direct access to the RMS data but the data in
the records needed to be broken out into fields.  I started putting
together a couple of modules to handle this.

I called the first module Formatter.  This class is presented with a
list of field names and pack/unpack descriptors.  It provides
subroutines to convert a record read from a file into a hash or convert
a hash back into a record that can be written to a file.

        # simple record
        my $fmt = new Formatter [ 'Field1:A6',  'IntField:i' ];
        my $hashref = $fmt->unformat($filerec);
        # $hashref->{Field1} contains the first 6 bytes from the record
        # $hashref->{IntField} contains a 32 bit integer value from bytes 7-10
        my $filerec = $fmt->format($hashref);
        # converts the hash above back into a 10 byte record

        # variant record - decodes with first format and invokes
        # chooser which returns index of format to use
        my $fmt2 =
            new Formatter {
                Chooser=>{ $RecTyp eq '0' ? 1 : 2; },
                Format=>[ [ 'Key:A6', 'RecTyp:A1' ],      # 'chooser' format
                          [ 'Key:A6', 'RecTyp:A1', ... ], # 'primary' format
                          [ 'Key:A6', 'RecTyp:A1', ... ]  # 'other' format
                        ] };

The second module is called FlatFile.  This class can be used either by
itself or can be used as a base which is what I did.  It uses
VMS::IndexedFile for file access and Formatter to convert data records
into Perl usable formats.

When used standalone:

        # open file 'filename.dat', $access = 0 for read, non-zero for write,
        # \@format is array of format specifiers as above, $keynum is key of
        # reference
        my $file = new FlatFile 'filename.dat', $access, \@format, $keynum;
        my $hashref = $file->get($key);  # keyed read
        my $hashref = $file->get('');    # sequential read
        $store_status =  $file->put($hashref);
        $delete_status = $file->delete($key);

When used as a base class, the derived class would represent a
particular file on the system and would provide the file name and format
arguments.  Programs using the derived class would specify the level of
access and key required.

With these modules, I was able to rewrite all eight inquiry programs in
two weeks.  I'll be looking into some data entry routines next.

Anyway, my reason for posting was to see if there was any interest in
these routines.  I'd also be open to suggestions for module and routine
names.  These were the best I could come up with on the spur of the
moment but I haven't been particularly fond of them.

I'll be cleaning them up and attempting to write some documentation for
them.  Once I'm done, I'll make them available from my web space on my
ISP.

-- 
tom_p
[EMAIL PROTECTED]
http://www.eclipse.net/~pfau/
Community Gospel Church information at http://www.cgcnb.org/

Reply via email to