Perl Programming Language
Perl Hello World
First published on September 9, 2019. Last updated on February 6, 2021.
Let’s begin with a simple Perl program. It will only display a simple message but contains several important parts.
print "Hello World!\n";
(On Windows, you may need to replace the first line with:
The first line tells your computer to run your program within the Perl environment. The next lines tell Perl to require strict coding and show warnings for violations.These lines are optional but recommended for learning.
The final line tells Perl to print your greeting message to the output device (which is probably your screen).
Notice how most of the lines end in semicolons. This tells Perl that you intend the line to end there. This is useful when you need to write a long line of code that actually takes up several lines of screen space.
There are several ways to run your Perl script.
You can save your code in a file that ends with “.pl”, which tells the computer that this is a Perl file.
Run a Perl program on a Unix or Linux machine by typing:
Or you can enter and run your Perl code at an online development such as ideone. (Beware the some environments might run different versions of Perl, so you may need to tweak your code to run on them.)
If you are having trouble, see the Troubleshooting lesson.