Techumber
Home Blog Work

How To Convert Perl To EXE

Published on November 14, 2014

I have been looking for one programming language which can be used to for web development as well as stand alone application development. Since, I’m a big fan of JavaScript I tried several options. One such tool is node-webkit. But it didn’t give me expected result. Then I found c++ in one good alternative for standard alone application but it’s really hard for web development. How To Convert Perl To EXE

Finally, I found Perl. Though, I’m new to Perl. I really enjoy it since it is almost like JavaScript. I found there are server common things between Perl and JavaScript. I think JavaScript is a light weighted version of JavaScript. If we taliking about eprl we should especially talk about cpan (Perl packages). Yes! We have thousands of Perl packages which will make your work smooth and slim. Again, if you are a windows user initially it’s really hard to setup the environment. Especially sometimes some Perl packages doesn’t support windows. But fortunately most cases you can find alternative packages for windows. Now, enough talking about Perl. Let’s see how we justify the post title by creating standerd alone application using form Perl source code. Before we start I’m assuming you already setup your Perl environment in your box. If not please check this post to how do it. //www.techumber.com/2014/08/create-restful-services-using-perl.html We can create binary version. Using several different tools. But here I’m going to use only these two tools.

  1. PerlApp (//www.activestate.com/perl-dev-kit)
  2. Perl2exe (//www.indigostar.com/perl2exe.php)

Unfortunately none of above are completely free. PerlApp Comes with 21 days trail period were as perl2exe is kind of free but it will leave a message below in your output binary. Anyway, I’m going to try with both. Download above two tools and install them. Make sure you set them under your windows environmental PATH Variable. Now, let’s write some Perl script which we want to convert into a standard alone application.

tuhtml.pl

#!/usr/bin/perl

use strict;
my $action = $ARGV[0];
my $param = $ARGV[1];
my $project_name = undef;
my $is_new_dir = undef;

main();

sub main {
    if ($action eq "init") {
        init();
    } else {
        help();
    }
}

sub init {
    print "Enter Project Name(default:MyProject):";
    $project_name = < STDIN > ;
    chomp $project_name;
    if ($project_name eq "") {
        $project_name = 'MyProject';
    }
    print "Do you want to create new dir(y/n)?(default:y):";
    $is_new_dir = < STDIN > ;
    chomp $is_new_dir;
    if ($is_new_dir eq ""
        and $is_new_dir ne "y") {
        $is_new_dir = "y";
    }
    if ($is_new_dir eq "y") {
        mkdir($project_name);
        chdir($project_name);
    }
    mkdir("img");
    mkdir("css");
    mkdir("js");
    create_index();
    create_css();
    create_js();
    print "Your ".$project_name.
    " component is ready";

}



#
for general help
sub help {
    print << "END_MESSAGE";
    -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
    Welcome to tuhtml
    v.01 beta;

    Usage: tuhtml[command]

    General Commands:
        tuhtml init# to create new scaffolding
    for you map component
    tuhtml help# general help
    END_MESSAGE

}


#
create css
sub create_index {
    open(my $fn, '>', 'index.html');
    print $fn << "END_MESSAGE"; < !DOCTYPE html >
        < html lang = "en" >
        < head >
        < meta charset = "UTF-8" >
        < title > $project_name form Techumber.com < /title>  < link rel = "stylesheet"
    type = "text/css"
    href = "css/style.css" >
        < /head>  < body >
        <!--[if lt IE 7]>
        < p class = "browsehappy" > You are using an < strong > outdated < /strong> browser. Please <a href="http:/ / browsehappy.com / ">upgrade your browser</a> to improve your experience.</p>  < ![endif] -->
        < h2 > Welcome to Auto Generated Project < /h2>  < script type = "text/javascript"
    src = "js/script.js" > < /script>  < /body>  < /html>
    END_MESSAGE
}#
crate css
sub create_css {
    open(my $fn, '>', 'css/style.css');
    print $fn << "END_MESSAGE";
    /*
     * html5 doctor css reset | //html5doctor.com/html-5-reset-stylesheet
     */
    html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup,
    var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video {
        margin: 0;padding: 0;border: 0;outline: 0;font - size: 100 % ;vertical - align: baseline;background: transparent
    }
    body {
        line - height: 1
    }
    article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
        display: block
    }
    nav ul {
        list - style: none
    }
    blockquote, q {
        quotes: none
    }
    blockquote: before, blockquote: after, q: before, q: after {
        content: none
    }
    a {
        margin: 0;padding: 0;font - size: 100 % ;vertical - align: baseline;background: transparent
    }
    ins {
        background - color: #ff9;
        color: #000;text-decoration:none}
mark{background-color:# ff9;
        color: #000;font-style:italic;font-weight:bold}
del{text-decoration:line-through}
abbr[title],dfn[title]{border-bottom:1px dotted;cursor:help}
table{border-collapse:collapse;border-spacing:0}
hr{display:block;height:1px;border:0;border-top:1px solid # ccc;
        margin: 1e m 0;
        padding: 0
    }
    input, select {
        vertical - align: middle
    }

    html, body {
        width: 100 % ;
        height: 100 %
    }
    END_MESSAGE

}#
crating javascrip
sub create_js {
    open(my $fn, '>', 'js/script.js');
    print $fn << "END_MESSAGE";
    //$project_name Main APP
    var App = (function() {
        //private
        var i = 0;
        //public
        return {
            init: function() {

            },
            some_other_fucntion: function() {

            },
        }
    }());
    App.init();
    END_MESSAGE
}

This code will generate a scaffolding for your html project. I know we have yomon to do it. It’s a mini version of it on Perl. Now to test your code what you can do it just got to your command prompt and type as Hope you already install active perl and set it up in your PATH.

perl tuhtml init

How To Convert Perl To EXE It will ask some question just answer them to create your project. Now, The interesting part. Let’s convert our Perl into standerdalone .exe application so we can distribute it without any chance of exploding our source code. PerlApp, Perl2Exe works exactly the same way. We will try with both of them separately. I hope you installed them and put them under PATH. Open your command prompt and go to location where you wrote your Perl script (Alternatively you can press shift and right click inside the folder where you wrote your Perl script). Run the following command.

perlapp tuhtml.pl

How To Convert Perl To EXE It will give you your binary distribution. Now, let’s use perl2exe to generate your exe file.

perl2exe tuhtml.pl

You can use any of bove to get your .exe file.