OS/2 eZine - http://www.os2ezine.com
Spacer
April 16, 2002
 
Brent R. Scott is employed as an Internet Network Engineer with a large telecommunications company. He is also working to obtain his Master of Science degree in Systems Engineering from George Mason University. On the side, he maintains a family web and mail service from his home.

During personal time, he and his wife enjoy playing music together (violin and piano) as well as doing home improvement projects on their house on the weekends.


If you have a comment about the content of this article, please feel free to vent in the OS/2 eZine discussion forums.

There is also a Printer Friendly version of this page.



Spacer
Previous Article
Home
Next Article


Try the new version of ThirdEye


Perl/2

Perl is a very versatile language. It was originally developed by Larry Wall for text processing. Since then it has grown into a powerful programming language used in many types of environments. Perl is easy to learn and FREE. It has been ported to most common operating systems including the beloved OS/2 Warp.

This article outlines the steps for installing and configuring Perl on OS/2 Warp 4 and Warp 4 Server. Of course it may work on other versions of OS/2 with other fixpaks, but was not tested for this article. ALWAYS be sure to back up the system before making any changes! The author is not responsible for any damage to the system resulting from the installation of Perl.


Prerequisites

  • OS/2 Warp 4 installed and working on an HPFS partition
  • Latest EMX run-time libraries are installed
  • Apache web server installed and functional (Needed for CGI scripting)
  • Programming experience (Preferably Perl)
  • HTML experience

Perl for System Administration

Installation

All packages can be obtained from CPAN: http://www.cpan.org/ports/index.html. Go to the section titled IBM OS/2 and click on the link. Reviewing the README.1st file is recommended, but not necessary. Download ALL zip packages for OS/2 into a temporary directory (i.e. C:\tmp\perl2). Though you can do a minimalist install, a full installation is always recommended. This will save the trouble of adding packages later and avoid limited functionality. A description of each zip file can be found in the README.1st file.

There are two ways to install Perl on OS/2: Manually or SoftInstaller. The remainder of this article will describe the installation using SoftInstaller included with the Perl packages that were downloaded. Unzip the files plINSTAL.zip and plinstl0.zip in the temporary directory where they were downloaded. This will be the installation directory containing all the zip packages. Once unzipped run the install.exe program file.


The O'Reilly camel associated with Perl appears on the screen with some brief instructions. Click continue to proceed. A dialog will appear prompting to update config.sys once the installation is complete. The README.1st file warns that SoftInstaller will change a chunk of the config.sys file to upper case which can cause problems for case sensitive entries. In order to save the modified copy to another file for review, uncheck the box. The modified file will be saved as config.add. You may wish to allow the program to update the config.sys for you, but do so at your own risk.

The next dialog box gives the list of all packages downloaded for installation. Select All and read the descriptions. The one package that may not be needed according to the descriptions is Perl a.out-style executable since this only works on DOS and Win (though may run under an OS/2 DOS window). The manpages are handy if running XFree86/2.

Be sure to review/edit the install paths. Make sure that the drive selected is valid and preferably the OS/2 installation drive. Some of the default paths (make sure they are correct!) place some libraries in the EMX directory. This is handy since it reduces the paths added to $PATH and $LIBPATH. This can be a problem if the EMX directory tree ever needs to updated or removed. The author used this structure:

  • Perl library: C:\EMX\PERLLIB\LIB
  • Perl execs: C:\EMX\BIN
  • Perl utils: C:\EMX\BIN
  • Perl dlls: C:\EMX\DLL
  • Pdksh exec: C:\EMX\BIN
  • Optnl library: C:\EMX\PERLLIB\LIB\SITE_PERL
  • PODS: C:\EMX\PERLLIB\LIB\5.00553\POD
  • Manpages: C:\xfree86\MAN
  • INF docs: C:\EMX\BOOK
  • READMEs: C:\EMX\PERLLIB
  • Install utls: C:\EMX\PERLLIB\INSTALL

Once all modifications are made to satisfaction, click on the install button. Approximately 19 Megs will be needed for the full installation. A dialog box appears showing the status and files being copied. This will take about 5-10 minutes depending on the machine. An OS/2 command prompt appears and executes a script to test the installation. A response indicates the success of the install.

If you chose to save the modified config.sys into a separate file, then compare the new file with the original and check for changes. Noticeable changes that should have been made is the addition of the following lines:

set PERL_BADLANG=0
set PERLLIB_PREFIX=f:/perllib/lib;C:\EMX\PERLLIB\LIB
set PERL_SH_DIR=C:\EMX\BIN

Double check for any other changes if the installation method varied from above. Copy these to the config.sys file, OR rename the original to config.perl and rename config.add to config.sys. Reboot the computer. If all went well, Perl should be fully functional.

Configuration

There really should be few configuration changes once Perl is properly installed. If installed properly, a Perl Maintenance icon will be located on the desktop. Open this and run the program Test Perl Installation. All checks performed should come back OK. The system is now ready for Perl Programming.

Usage

This section will not teach how to program in Perl since that is beyond the scope of this article. However, some OS/2 specific syntax will be briefly discussed. Some good web references for learning Perl are www.perl.org and www.perl.com. A highly recommended printed reference and learning tool are the O'Reilly books. A collection of five books can be purchased on CD ROM titled The Perl CD Bookshelf.

In order for a Perl script to execute, every script must be told to use an external batch processor other than the OS/2 batch processor. This is done by placing the following line at the start of every script:

extproc perl -S

This has the same effect as unix #!/usr/local/bin/perl. In order to execute the script from a command line, the file extension will need to be 'cmd'. This is also different from the typical unix naming convention using 'pl'. So a program named perlscript.pl under unix, will be named perlscript.cmd under OS/2. Other OS/2 specific syntax structures can be found in the documentation installed with Perl (you did install it, right?)

This should give the tools needed to perform system administrative tasks on OS/2 such as scripted log rotating. Of course, Perl is not limited to just system administration, but can be used for many other tasks such as data manipulation or cgi scripting as well. Setting up Perl for Web development on OS/2 is discussed below.

Perl for CGI Scripting

Installation

If the machine on which the full Perl distribution has been installed as outlined above is the same machine on which Apache resides, then do not reinstall Perl. Skip to the section Configuring Apache. As noted above, all packages can be obtained from CPAN: http://www.cpan.org/ports/index.html. For a full installation follow the instructions listed above. For a minimalist installation, download the files plINSTL0.zip, plINSTAL.zip, and perl_exc.zip into a Perl installation directory such as C:\tmp\perl2. Follow the remainder of the instructions listed above, skipping over reference to packages not being installed. Again, it is highly recommended to do a full installation.

Configuring Apache

The configuration at this point should be minimal, as well, if you installed Perl as outlined above. You should also have Apache already installed and functioning. You can find information on Apache for OS/2 at an old OS/2 eZine Article or at the Apache for OS/2 web page.

There are a few specific details relating to cgi scripting support. Make sure your httpd.conf file contains a line that calls the cgi module. It should look something like this:

LoadModule cgi_module libexec/cgi.dll

This should be a default entry in the configuration file. Make sure there is an entry that sets the location for cgi scripts which is commonly called cgi-bin. There should be a line that looks like this:

ScriptAlias /cgi-bin/ "/home/httpd/cgi-bin/"

This entry is specific to the installation of apache. Edit it accordingly. There is one more entry to check. It should look something like this:

<Directory "/home/httpd/cgi-bin">
AllowOverride None
Options None
Order allow.deny
Allow from all
</Directory>

Be sure to edit this according to the specific Apache install as well.

Usage

The usage is similar to that already described with a few additions. Of course the script should have a 'cmd' file extension and call the Perl batch processor as described above. File access follows the standard Perl structure with '/' representing the top level directory of the drive (or partition) from which the script is executed. This means that the script can only access files on the drive (or partition) from which it is executed. There may be a way to access other drives, but it is not known to the author at this time. One last parameter that is needed for cgi scripting is to always tell the browser what the content type will be. This is done with:

print "Content-type: text/html\n\n";

Here is a summary example that combines a simple Perl script that opens a directory, assigns file names to an array, closes the directory, then prints the contents, with hyper links, to the web browser. Yes, it does work. (-=

extproc perl -S
#
# perlCGI_test.cmd
#
# This script tests Perl as a CGI for Apache on OS/2.
#
# Brent R. Scott

print "Content-type: text/html\n\n";
print "This is a test of Perl as a CGI under Apache for OS/2.<BR>";

opendir(WEBDIR,"/home/httpd/html");
@files = grep (/\.gif/, readdir(WEBDIR));
$fcount = @files;
closedir WEBDIR;

print "Number of files found: ", $fcount, "<BR>";

for ($i = 0; $i < $fcount; $i++ ) {
print "File in position ", $i+1, " <A HREF=\"/$files[$i]\"> ", $files[$i], "</A><BR>\n";
}

Conclusion

With its diverse application, Perl is a beneficial and worthwhile language to learn. With the right references, learning should be quick and simple. Of course, some prior programming experience always helps. When problems arise, there are plenty of resources for resolution. IRC channels (#perl) are a quick way to speak with talented programmers that can give suggestions. Looking at the apache log files will point to reasons for failed cgi scripts. Putting the time to read web pages and reference books about Perl will always give much insight into debugging and efficient coding. This is all you need to become a Perl programmer on OS/2.

Previous Article
Home
Next Article

Copyright (C) 2002. All Rights Reserved.