Running PerlApp to Convert *.pl to *.exe

This section provides a tutorial example of running PerlApp from ActiveStat to convert a sample Perl script, DirGrep.pl, to Windows executable binary, DirGrep.exe.

Running PerlApp to convert a Perl script to an executable program is simple. Let's take my DirGrep.pl as an example:

#- DirGrep.pl
#- Copyright (c) HerongYang.com. All Rights Reserved.
#
   ($expression, $dir) = @ARGV;
   die "Missing regular expression.\n" unless $expression;
   $dir = "." unless $dir;
   $fileCount = 0;
   $matchCount = 0;
   $textCount = 0;
   $otherCount = 0;
   &loopDir($dir);
   print "Number of matched lines = $matchCount\n";
   print "Number of files with matched lines = $fileCount\n";
   print "Number of text files searched = $textCount\n";
   print "Number of other files not searched = $otherCount\n";
   exit;
sub loopDir {
   local($dir) = @_;
   local(*DIR);
   opendir(DIR, $dir) || die "Cannot open $dir\n";
   while ($f=readdir(DIR)) {
      next if ($f eq "." || $f eq "..");
      $f = "$dir\\$f";
      if (-d $f) {
         &loopDir($f);
      } elsif (-T $f) {
         $textCount++;
         if ($n=&fileGrep($f)) {
            $matchCount += $n;
            $fileCount++;
         }
      } else {
         $otherCount++;
      }
   }
   closedir(DIR);
}
sub fileGrep{
   local($file) = @_;
   open(IN, "< $file");
   $n = 0;
   $l = 0;
   while(<IN>) {
      $l++;
      if (/$expression/i) {
         $n++;
         print "$file, line $l\n" ;
         print;
         print "\n";
      }
   }
   close(IN);
   return $n;
}

Run the following commands to convert it into a Windows executable program and test it:

herong> \pdk\bin\perlapp DirGrep.pl

PerlApp 6.0.1 build 138990
...
* WARNING: Applications generated by this evaluation copy of PerlApp
*          will stop working after the end of the evaluation period.
...
Created 'DirGrep.exe'

herong\src> DirGrep binary ..

...
..\htm\binary.html, line 18
<li>How to open files for input in binary mode.

..\htm\binary.html, line 20
<li>How to open files for output in binary mode.
...

As you can see from the output, the converted program DirGrep.exe works nicely. Now I can pass my DirGrep tool to anyone who is using Windows system without Perl installed.

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Image and Picture Processing

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server

 CGI.pm Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

Converting Perl Script to Executable Binary

 Perl Script Conversion Tools

 Installing Perl Dev Kit (PDK)

Running PerlApp to Convert *.pl to *.exe

 Managing Perl Engine and Modules on macOS

 Archived Tutorials

 References

 Full Version in PDF/EPUB