Installing PAR::Packer (in Windows or Linux)

I’m a frequent Ubuntu Linux user. I don’t use Windows much, unless I’m at work. Today, I wrote a small script to parse Apache access logs and thought, “This would be a really cool utility to share with others.” Granted, it’s pretty basic and there are most likely hundreds of other utilities out there, so I’ve decided to use it as an example to installing PAR:Packer under Windows to compile perl scripts into a Windows executable.

  1. Download and install Strawberry Perl
  2. Install cpanm to more easily install CPAN modules. In a command prompt, run: ```bash cpan -i App::cpanminu

  3. Then install **PAR::Packer** for _compiling_ the Perl script. Run: ```bash
cpanm -n PAR::Packe

Continue reading for an example!

An example script

The following script is a simple perl script to parse apache logs for a given HTTP status code (default is 200).

View the gist on GitHub.

‘Compiling’

The PAR::Packer module doesn’t actually compile this script. It creates an executable which embeds Perl and the script and executes the script using the embedded Perl executable. Sounds a little weird, but it’s pretty cool. I’m writing this under Linux, so use ‘dir’ instead of ‘ls’ to view files in the current directory, and execute the file as you normally would (filter_logs.exe instead of ./filter_logs.exe).

To create the executable, run:

pp -o filter_logs.exe filter_logs.pl

Now, you can execute filter_logs.exe against some log file! Here’s some example output from my Ubuntu machine:

jim@schubert:~/Documents/examples/perl/blog-2011-07-20$ pp -o filter_logs.exe filter_logs.pl 
jim@schubert:~/Documents/examples/perl/blog-2011-07-20$ ls
access.log  access.log.1  access.log.2  filter_logs.exe  filter_logs.pl
jim@schubert:~/Documents/examples/perl/blog-2011-07-20$ ./filter_logs.exe access.log.2 200 | head -15
Originally requested:	OPTIONS * HTTP/1.0
              status:	200
                path:	-
                size:	152
              client:	Apache/2.2.17 (Ubuntu) (internal dummy connection)
Originally requested:	OPTIONS * HTTP/1.0
              status:	200
                path:	-
                size:	152
              client:	Apache/2.2.17 (Ubuntu) (internal dummy connection)
Originally requested:	OPTIONS * HTTP/1.0
              status:	200
                path:	-
                size:	152
              client:	Apache/2.2.17 (Ubuntu) (internal dummy connection)
jim@schubert:~/Documents/examples/perl/blog-2011-07-20$ ./filter_logs.exe access.log.2 404 | head -15
Originally requested:	GET /humans.txt HTTP/1.1
              status:	404
                path:	-
                size:	501
              client:	Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.24 Safari/535.1
Originally requested:	GET /humans.txt HTTP/1.1
              status:	404
                path:	-
                size:	500
              client:	Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.24 Safari/535.1
Originally requested:	GET /humans.txt HTTP/1.1
              status:	404
                path:	-
                size:	500
              client:	Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.24 Safari/535.1

When using PAR::Packer under Linux, you don’t need to have the .exe extension. I did this only as an example.

Note: you can easily install PAR::Packer in Ubuntu with:

sudo apt-get install libpar-packer-perl 

Related Articles