Hello World

This lesson gets you acquainted with the Hello World program in Perl.

We'll cover the following

Why “Hello World”?

The first program that most aspiring programmers write is the classic and the simplest “Hello World” program. The purpose of this program is to display the text “Hello World” on the screen.

Syntax

Try running the code below:

Press + to interact
print "Hello World";

In the above example, we have used the print keyword to display the text Hello world on the screen. Programmers familiar with the C programming language will be happy to know that the C printf() function also works in Perl. So, the syntax would look like:

Press + to interact
printf("%s", "Hello World");

In the above code, printf is used to display the text. The %s is used as a format specifier to let the command know that a string will be printed (which in this case is “Hello World”).

Key takeaways

  • print or printf keyword is used to display text
  • Any text that we want to print goes in pair of double quotes " "
  • Every statement in Perl ends at ; unless it is the final statement in a block, in which case the semicolon is optional