Hello, World! A classic start

Ever since Brian Kernighan wrote the book "The C Programming Language", the basic program to test a new language has been "Hello, World!". "Hello, World!" is a program that prints "Hello, World!" on the screen. So to start of this Perl tutorial, we will learn how to write a "Hello, World!" program in Perl.

The programming motto of Perl is TIMTOWTDI, which is pronounced Tim Toady. TIMTOWTDI stands for "There's more than one way to do it. This means that in Perl, one problem will have multiple solutions and more importantly multiple different tools are provided to solve that problem. This article will provide multiple examples, to showcase some of the different methods to solve the problem. First a short example:

#!/usr/bin/perl use strict; print "Hello, World!\n";

The first part of this program is what is called a shebang. The shebang tells the shell which interpreter will run the script, in this case it is perl. The shebang consists of two parts, the first being #!. The second part is the path to the interpreter. To find the path to perl, you can type which perl in the terminal.

After the shebang comes the actual script. This script is one line long and outputs the line "Hello, World!" to the terminal.

Another way of printing text is the use of a here document. A here document is a way to print an entire block of text. First an example:

print << END_OF_BLOCK; Hello, World! END_OF_BLOCK

print "Hello, World!\n"; print("Hello, World!\n"); print STDOUT "Hello, World!\n"; print(STDOUT "Hello, World!\n");