PERLS FROM WISDOMBAY

A technology Blog from the creator's of http://www.wisdombay.com . This Technoblog is meant to be a One Stop Shop for PERL Programmers. Here I am planning to keep a frequently updated journal filled with code, tutorial's and tips for PERL Lovers.

Tuesday, April 11, 2006

Some more blah blah on how to execute a Perl program

Welcome back !!.

The work is over for today and I thought a little bit of Perl class would be fine to get my tired mind back on track.

In Last class we talked about, hmm rather blogged about, how a perl program gets executed. In this class I will tell you the various methods by which a Perl program Can be executed (there are many way’s) and will talk a bit about command line options available for developers of Perl programs.

The various flavours of execution available for Perl programs

1. In windows machines, you can make the .pl extension registered with the perl interpreter, so that double clicking on a Perl source code file will make it execute. Installing Activestate’s Perl set’s up this automatically on your machine.
2. On your Unix flavored boxes, providing shebang statement (like #! /usr/bin/perl) in your code can make the Perl program to run as an executable provided that an executable permission is set for the file.
3. You can run Perl code on a windows machine by double clicking the perl interpreter executable and then typing your code in the resultant window. After typing in your Perl code, type CTRL + Z and an Enter key to execute the typed in Perl code. This can be done on your Unix/Linux machines also.
4. You can execute a Perl source code by typing perl followed by the source code name, like ‘perl mycode.pl’.
5. Execute single line code using ‘perl –e’ switch. The –e switch allows multiple commands given as a single line to be executed right from command line.

The format to be used on Windows machines for this is Perl –e “ command ”
ex : perl -e "print \"hello\";print \"\n Another line \" "

The above example prints

hello
Another line


In windows machines the command is to be enclosed in double quotes and any further double quotes that are to be inputted inside it are to be escaped using the ‘\’ (slash) character.

The format for Linux/Unix machine is perl –e ‘command’

ex : perl -e ‘print "hello";print "\n Another line" ‘

In Linux/Unix machines the command is to be enclosed in single quotes.


Command line utilization

Command line arguments or switches are little combination of characters which will tinker the way in which the Perl interpreter acts on a command or a script name. Switches are usually preceded by a '–' symbol. To see all the available command line options in your installed version of Perl, use the below command.

perl --help

You can use the switches as a combination or a as single units. For example if you have to specify two command line switches ‘V’ and ‘W’ in the same command you can use the below two ways.

perl –VW ‘file.pl’
or
perl –V -W ‘file.pl’


Surprise, Surprise – Perl does have a compiler

Even though perl lacked a compiler in it’s initial evolutionary stages, some where around the middle 90’s, the perl 5.005 version, started to incorporate a native compiler. This finally made perl programs free from the mercy of the must have presence of a perl interpreter at the target or client machine. Using this compiler, Perl scripts can be compiled into binary form and Software’s done on perl could be provided as standalone packages with out the need of an interpreter.

Read more on B – The Perl Compiler Here

So we will surely meet in our next class, and there we will be having a look at the practical side of Perl programming. We will start with the Basic’s of Perl language in the next session.

0 Comments:

Post a Comment

<< Home