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) 1995 by Dr. Herong Yang, http://www.herongyang.com/
#
($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:
>\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'
>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.