ansh batra has asked for the wisdom of the Perl Monks concerning the following question:

hi monks
i have written a perl script and now want to convert it into a debian(executable).
is this posible??
if yes then please give me some tips and resource/urls.
i am totally new to linux
thanks
  • Comment on how to make a debian of a perl program.

Replies are listed 'Best First'.
Re: how to make a debian of a perl program.
by davido (Cardinal) on Oct 17, 2011 at 05:31 UTC

    I think that you're asking how to make it so that Linux can execute a Perl script you've written, as opposed to the other possible interpretation which is how to make a binary executable out of a Perl script. In the context of a linux environment where having a Perl interpreter installed is fairly ubiquitous, the latter interpretation doesn't seem to me what you're asking. But if I'm wrong, you may want to clarify.

    Debian is a flavor of Linux, and any normal installation of Debian Linux would have Perl installed already. So executing is just a matter of making sure the proper modules are in place, and then moving on to the following:

    This is mostly a Linux question, with one Perl component to it. So let's get the Perl part out of the way:

    The first line of your script needs a "shbang line", which tells the shell where to find the Perl interpreter. That may be something like this:

    #!/usr/bin/perl

    Or it may be something else. If you type "which perl" at your shell you will see a path to Perl. To keep things simple you can usually just use that path, with the #! prepended to it as the first line of the script. Later on you may choose a more flexible shbang option.

    Now on to the Linux component of the question. By typing the following:

    chmod +x scriptname

    (Thanks AnonymousMonk for catching my typo.)

    You will be telling Linux that the file named "scriptname" is an executable.

    The final step is to know how to invoke it. It either needs to be in a folder that is part of your path, or you will need to invoke it by qualifying the path. If you have to do the latter, just 'cd' into the folder where the script is and type ./scriptname

    The ./ part is telling your system that the file you want to execute is in the current working directory. Otherwise the system will go looking for it in one of the directories specified in your path environment variable; eg, usually the various 'bin' directories, and possibly a few other places.


    Dave

      It's actually chmod +x scriptname (or chmod 755), and I read his question as "How to create a debian package", which is a completely different kettle of fish, and definitely not something I'd try. In any case, here's an IBM DeveloperWorks article on the subject.

      But if you need to install a single script non-portably, install -m0755 scriptname /usr/local/bin/ is all that you need.

        chmod +x scriptname Of course you're exactly right. Where's my head tonight? Updated.

        The intent of the question is at best ambiguously presented.


        Dave

Re: how to make a debian of a perl program.
by GrandFather (Saint) on Oct 17, 2011 at 05:27 UTC

    Scripts generally can't be turned into executables and that is especially true for Perl. However you can package your script up so that it runs as though it were an executable. Generally that is done by packaging the Perl interpreter along with the script and any modules that are required by the script into an executable file that unpacks everything when it is run then transfers control to the unpacked interpreter to run the unpacked script. This imposes some overhead so, depending on your application may not be suitable.

    True laziness is hard work
Re: how to make a debian of a perl program.
by pvaldes (Chaplain) on Oct 17, 2011 at 09:02 UTC
    dh-make-perl

    Any (valid) perl script is executable in Debian when you set this option with chmod, but what you want probably is to pack a perl script in a .deb package.