Inside the New Perl Resource Kit

The new kit will significantly affect the Windows NT and Perl communities.

Bob Wells

August 31, 1998

8 Min Read
ITPro Today logo in a gray background | ITPro Today

Perl for Win32 takes a quantum leap forward

Quantum leaps of functionality in well-established technologies, especially programming languages, aren't common. However, Perl Resource Kit--Win32 Edition is a quantum leap for Perl on the Win32 platform. The Perl resource kit is a product of O'Reilly & Associates, but ActiveState Tool contributedthe new Win32 Perl software on the kit's CD-ROM. The resource kit contains advances in functionality that will significantly affect the Windows NT and Perl communities. These advancements include a new release of Perl, new tools and utilities, and extensive documentation.

New Release of Perl
The most significant advancement in the Perl resource kit is the release of Perl 5.005. This version consolidates the two most popular Win32 builds of Perl: CORE and Perl for Win32. Before version 5.005, users chose between these Win32 Perl implementations because the two builds offered different functions in some areas and implemented the same functions differently in others. Their disparity resulted in code that ran under one build but not the other. Version 5.005 effectively merges the two builds into one comprehensive package that eliminatespast incompatibilities.

Fortunately, there are only minor code incompatibilities between version 5.005 and previous versions of CORE and Perl for Win32. The area primarily affected deals with Object Linking and Embedding (OLE) support. People who used ActiveState's OLE implementation will need to change the way they instantiate and access objects. This incompatibility and the other minor incompatibilities are well documented in the resource kit's release notes.

New Tools and Utilities
Perl 5.005 isn't the only software in the Perl resource kit. The kit also includes ActiveState's Perl Debugger, Perl for Internet Server API (ISAPI), Perl for Website, PerlScript, and Perl2Exe. Three new commercial software packages that I like are Perl Package Manager (PPM), PerlCOM, and PerlCtrl.

PPM. With PPM, users easily install, manage, and remove add-on Perl packages. Packages are third-party libraries, such as modules and extensions, that extend Perl's capabilities. For example, the Win32::AdminMisc module I discussed in last month's column ("How to Manage Your Enterprise's Passwords the Easy Way," August 1998) is a package.

If you are a long-time Perl user, you probably know about the hassles involved with installing, managing, and removing packages. For example, if you install a new version of Perl, you must verify that the code in your existing modules doesn't break. If problems arise, you must find a module update that is compatible with the new version of Perl. If an update module isn't available, you remove the Perl upgrade and wait until the module developer releases an updated version. Another problem users encounter when installing packages isthat some packages require numerous installation steps, including a compilation phase that is beyond the scope of many Perl users.

With PPM, configuring third-party Perl packages is a snap. PPM comes in two versions: a console-based version, which retains the name PPM, and a browser-based version, Visual Package Manager (VPM). PPM and VPM have three primary functions: Install, which installs a new package from a specified repository URL; Remove, which removes a currently installed package; and Verify, which verifies whether an installed package is up-to-date and optionally updates the package if it's not.

Installing packages with VPM takes only a few mouse clicks. You select the URL repository, select which packages you want to download, and click Install, as Screen 1, page 196, shows.

Only time will tell how useful VPM and PPM will be. However, my prediction is that these two management tools will reduce the complexity and frustration with using third-party packages.

PerlCOM. With PerlCOM, you create instances of Perl and Perl modules from within any programming environment that supports Microsoft's component object model (COM), including Windows Scripting Host (WSH), Visual Basic (VB), Visual Basic for Applications (VBA), and Delphi. A PerlCOM.Script object makes PerlCOM's magic possible.

PerlCtrl. With PerlCtrl, you build COM automation servers in Perl. A COM automation server is a self-contained reusable .dll file that exposes methods and properties that any COM controller can instantiate and use.

With the Perl resource kit, using third-party packages is a snap.

The difference between PerlCOM and PerlCtrl is that PerlCOM is a COM automation server that exposes the PerlCOM.Script object and associated methods. PerlCtrl lets you build your own COM servers complete with their unique GUIDs and ProgIDs. ProgIDs are the friendly names you use to refer to an object class. For example, PerlCOM.Script and WScript.Shell are ProgIDs. Let's look at a PerlCOM example. I'll demonstrate PerlCtrl in a future column.

PerlCOM in Action
Suppose you want to use WSH with Visual Basic Script (VBScript) to execute an external command and capture the command's standard output. Although you can use WSH's Run method via the Shell object to execute the command, no simple method exists to capture the command's output. Instead, you must redirect the command's output to a file, open the file, parse it, close it, and finally delete the file.

Executing a command and capturing its output are much easier with the Perl resource kit because you can execute the Perl code via the PerlCOM object. The example BackTicks.vbs script inListing 1 shows you how to create and use a PerlCOM object. Let's examine how this script works.

Like other objects used from within a WSH script, you first need to create an object of type "PerlCOM.Script" to execute Perl code. At callout A in Listing 1, the PerlCOM object is objPerlCOM. You use the EvalScript method to execute standard Perl code. With EvalScript, you can create Perl variables that become properties of the PerlCOM object, or define Perl subroutines that become methods of the object.

After creating objPerlCOM, the script creates a new scalar variable(sProperty) and initializes it with the string to the right of the assignmentoperator (=). You must enclose the Perl code that you want to pass to EvalScriptin double quotes. The script then uses the standard VBScript MsgBox function anddot notation to access and display the property's value.

The code at B uses EvalScript to define the Perl subroutine, vbsBackTicks. This subroutine becomes the method that executes the external command and returns the command's standard output as a string. You must enclose the Perl code that you pass to EvalScript in double quotes. When the code spans several lines, you must use VBScript's line continuation character (_) and string concatenation character (&) to ensure that the script passes the entiresubroutine to EvalScript as one string.

Like sProperty, the vbsBackTicks subroutine is basic Perl code. Thesubroutine begins by initializing the two local scalars, $command and$delimiter. (When the script later invokes vbsBackTicks, the script passes these values to the subroutine.) The next line of the subroutine executes the user-defined command using Perl's backtick operator (`) and assigns the command's output to the @output array. The subroutine's last line uses Perl's join operator and the user-defined delimiter to translate the array into a string and return the string to the calling object.

The next line in the script calls the vbsBackTicks method and passes the desired command ("net use") and delimiter ("@") to the vbsBackTicks method. The variable sOutput stores the value vbsBackTicks returns. The script uses VBScript's MsgBox function to display the output. The last line in the script uses VBScript's Nothing keyword to destroy the objPerlCOM objectbefore the script ends.

After you run the BackTicks.vbs script, you will see the message boxes inScreen 2 and Screen 3. But PerlCOM's magic doesn't end here. You can use PerlCOMto create instances of Perl modules. With PerlCOM, you can extend Perl modulesto any COM programming environment. For example, WSH doesn't provide a mechanismto read from or write to NT's event logs. You can use PerlCOM to create aninstance of the Win32::EventLog module, making its functions available to WSH.

Extensive Documentation
The Perl resource kit features four volumes of documentation, totaling morethan 1500 pages. Whether you're a novice or expert Perl programmer, you'll findthe information in the four volumes of documentation useful.

The first volume is the Perl Utilities Guide, which covers the PerlResource Kit's installation and setup, Perl language basics, and Perlprogramming for Web servers (including information specific to all major Webserver platforms). This volume also contains the documentation for all thesoftware included in the kit. The second module is Programming with PerlModules, which teaches you how to leverage the hundreds of reusable Perlmodules available from the Comprehensive Perl Archive Network (CPAN) athttp://www.perl.com/CPAN. Programming with Perl Modules alsoteaches you how to create modules. The third and fourth modules constitute thePerl Module Reference. This two-volume set includes a comprehensivemodule index from which you can easily locate detailed module descriptions andusage instructions for hundreds of Perl modules.

A Significant Event
If you wrote BASIC programs in the late 1980s, you'll probably agree that what Microsoft has done to evolve the BASIC language is remarkable. You can say the same for what O'Reilly, ActiveState, and the Perl developer community have done for Perl. With a common code base in Perl 5.005, new utilities, new tools, and extensive documentation, Perl clearly becomes the most comprehensive scripting environment available for the Win32 platform.

You can purchase Perl Resource Kit--Win32 Edition from many retail bookstores. You can also purchase it online from O'Reilly & Associates (http://www.ora.com) and various online bookstores.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like