By Charles Galpin
Two key areas for improving Perl programming are achieving better support for Win32 and efficiently producing an executable version of your program. Here, we've rounded up a couple of tips to address these issues. Our first tip will point you to an excellent source for Win32 modules and an abundance of other hard-to-find modules.
Our second tip will help make the process of compiling your Perl program more straightforward. We'll introduce a command-line utility that can make the process more like the compile process of other languages. The benefits include protecting your source code and separation from the interpreter.
Perl has adequate support for Win32 programming, but the core distribution can be lacking in some areas. Contributors have added on to the standard distribution, and a good source for these modules is Jenda's pages.
This site includes a slew of Win32 and other modules that work very well and are difficult to find elsewhere. You should first download Win32::Lanman and Win32::FileType. Win32::Lanman gives a Perl API to the Win32 LAN manager back end, which controls user logins, passwords, and all settings related to the network and policy management. Win32::FileType obviously allows access to the Windows file types; it provides an API that allows you to associate (and change the association of) file extensions and their appropriate application programs.
Jenda's also offers a Mail::Sender package that features an object-oriented interface to SMTP on a variety of platforms, including Windows. There are several Mail packages available for Perl, but this one is noteworthy for its robust support options.
As a scripting language, Perl does not compile easily into executable files. The standard solution for creating executable files based on Perl code is to use the Perl compiler to create C output (-M preprocessor options), which can then be converted to an executable file. However, the C code created by the Perl compiler is typically far from usable. If you want equal, clean code that you can use in C, you usually need to rewrite the Perl program in C.
Luckily, there's another option. Perl2Exe is a command-line utility that converts Perl code into an executable for almost any mainstream platform (Win32, Solaris, Linux, AIX, etc.). Perl2Exe output files can operate independently of both the Perl interpreter and Perl source code. The only notable disadvantage to the program is that it runs at about the same speed as a normal Perl script with a standard interpreter. For more information about Perl2Exe, visit the IndigoSTAR Web site.
Do you have any Perl tips you would like to share?
If you have any Perl tips or tricks that you think others would find useful, we would like to hear about it. Send us an e-mail with your ideas and suggestions.