Perl Tutorials - Herong's Tutorial Examples - v6.03, by Herong Yang
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
Data Types: Values and Variables
Expressions, Operations and Simple Statements
Name Spaces and Perl Module Files
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 Directories and Read File Names
File System Functions and Operations
Socket Communication Over the Internet
XML::Simple Module - XML Parser and Generator
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
►Running PerlApp to Convert *.pl to *.exe