Perl - Hello World


The First Script


The first and foremost task with any new programming language is the Hello World. So also with Perl.
Before that, we have to start with installing the Perl interpreter. Perl normally comes pre-installed with Linux and Mac but we need to install it on Windows. We can obtain it from the Perl Website.
Once the interpreter is setup, we can go ahead with the first script. Windows associates the extension with application used run the file. Once the Perl interpreter is installed, the .pl extension gets attached with the interpreter and the job is done.
But that is not the case on a Linux (or Unix) - where a "real" Perl script will normally run. On a Linux, the interpreter is specified by the first line of the script. The first line in any kind of script is very important. It is called the "Shabang" line. It should like something like this:
#!/bin/perl
The #! is called the Shabang. What follows it is the path to the interpreter executable. It could be /bin/ksh or /bin/python or /bin/bash ... depending on the kind of script we create. It is customary (not necessary) to leave a line after the Shabank. After that comes the line of code
print "Hello World\n";
No marks for guessing.. This prints out the text Hello World. Thus the helloworld.pl script looks like this:
#!/bin/perl

print "Hello World\n";
Save this in a file. Change the permissions (on Linux) and run it. There we see on the console: Hello World. Nothing much for the world. But it is an assurance that we have started well.