Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compile my Perl script so it can be executed on systems without 'perl' installed?

Tags:

perl

I have a .pl file and I want to execute that file in any system even though perl is not installed. How can I achieve it?

What would be some good examples to do that?

like image 491
User1611 Avatar asked Aug 06 '09 06:08

User1611


People also ask

Can Perl scripts be compiled?

Since version 5.005, Perl has shipped with a module capable of inspecting the optimized parse tree ( B ), and this has been used to write many useful utilities, including a module that lets you turn your Perl into C source code that can be compiled into an native executable.

Do you need to compile Perl?

Perl is an interpreted language, which means that your code can be run as-is, without a compilation stage that creates a non-portable executable program. Traditional compilers convert programs into machine language.


2 Answers

pp can create an executable that includes perl and your script (and any module dependencies), but it will be specific to your architecture, so you couldn't run it on both Windows and linux for instance.

From its doc:

To make a stand-alone executable, suitable for running on a machine that doesn't have perl installed:

   % pp -o packed.exe source.pl        # makes packed.exe    # Now, deploy 'packed.exe' to target machine...    $ packed.exe                        # run it 

(% and $ there are command prompts on different machines).

like image 55
ysth Avatar answered Oct 09 '22 08:10

ysth


  1. Install PAR::Packer. Example for *nix:

    sudo cpan -i PAR::Packer

    For Strawberry Perl for Windows or for ActivePerl and MSVC installed:

    cpan -i PAR::Packer
  2. Pack it with pp. It will create an executable named "example" or "example.exe" on Windows.

    pp -o example example.pl

This would work only on the OS where it was built.

P.S. It is really hard to find a Unix clone without Perl. Did you mean Windows?

like image 41
Alexandr Ciornii Avatar answered Oct 09 '22 07:10

Alexandr Ciornii