Hello World (Perl Script)

You have to start somewhere.

If your just starting out no matter what the language your probably going to start with a very basic program and then learn from there. We call this a “Hello World” Script. here is an example of a hello world script in written in Perl.

First create a new file using vi

vi helloWorld.pl

Every perl script starts with a header. I also recommend you use a few modules called warnings and strict as well. Add these lines to the beginning of your file.

#!/usr/bin/perl

use strict;

use warnings;

Now you have the beginnings of a Perl script, but it doesn’t do anything. So lets add a basic function, print, to our script. The line is very simple. It will print out Hello World follow by a newline.

Add the following lines to your script:

print "Hello World!\n";

Save and Exit your file and then make it executable:

chmod +x helloWorld.pl

Now run the script and you should get this output:

./helloWorld.pl

Hello World

There you have a simple Hello World perl script. Like I said its very basic but shows you how to get started with perl. In the coming chapters we will cover more in-depth fundamentals such as Scalars, Hashes, and Arrays.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *