Hello World in Perl

Hello World in Perl Featured Image

Thanks for swinging by for another installment of the Hello World in Every Language series. Today, we’re playing around with Hello World in Perl, a language developed back in 1987.

Table of Contents

Perl Background

Just like normal, I took to Wikipedia to learn more about PerlOpens in a new tab..

As it turns out, Perl is actually a family of languages sort of like LispOpens in a new tab.. However, Perl is mainly divided into two branches: Perl 5 and Perl 6. As you can probably imagine, Perl 5 will be the language we’ll be using for this exercise. Perl 6 is actually a major deviation from the traditional language, so I’ll probably do a separate tutorial entirely for that language.

At any rate, Perl is a multi-paradigm language, so we’ll be diverging a bit from our functional trend in this tutorial. Instead, we’ll be working with a language that resembles languages like PythonOpens in a new tab. or COpens in a new tab..

In terms of features, Perl is a mixed bag, literally. That’s because Perl draws its inspiration from several other languages including C, Lisp, and AWK. As a result, Perl supports associative arrays, lists, regular expressions, and first-class functions. In fact, modern Perl even support object-oriented programming.

As a fun tidbit, Perl differs dramatically from Python in terms of complexity. In fact, the creators of Perl live by the slogan “there’s more than one way to do it.” In contrary, the creators of Python prefer that “there should be one — and preferably only one — obvious way to do it

Hello World in Perl

Without further ado, let’s dive straight into our implementation of Hello World in Perl:

print "Hello, World!";

Well, that was anticlimactic. In fact, it was about as disappointing as our implementations of Hello World in Python and Ruby. That said, who doesn’t love a simple implementation (talking to you, Java).

At any rate, let’s dig into this a little bit. For starters, we’ll notice there are no parentheses required for Perl’s print function. I use the word “required” because we can actually call print with them:

print("Hello, World!");

However, from my understanding, it’s good Perl style to omit the parentheses for built-in functionsOpens in a new tab..

Oh, I should probably clarify something. In Perl, they’re not called functions. Instead, they’re called subroutines, and you can declare one of your own using the sub keyword. That’s a new one for me!

How to Run the Solution

As usual, we can try the solution using an online Perl interpreterOpens in a new tab.. All we have to do is drop the code into the editor and hit run.

As an alternative, we can always run Perl locally. First, we’ll need to get the latest version of PerlOpens in a new tab. from the official website. After that, we should probably get a copy of the solutionOpens in a new tab.. Assuming Perl is now in our path, we can get to work:

perl hello-world.pl

Since Perl is a scripting language, we can quickly run the script with the command above. If successful, “Hello, World!” should print to the console.

Sample Programs in Every Language

And, that’s it for Hello World in Perl. I apologize for moving away from functional languages, so to make up for it I’ll be covering Scala and Elixir next. After that, I’ll probably be moving away from functional languages.

Once again, if you enjoyed this article, consider sharing it with your friends. Oh, and don’t forget to share your language recommendations in the comments. Those help me figure out what languages people are actually interested in seeing.

Sample Programs in Every Language (44 Articles)—Series Navigation

For 100 Days of Code, I’ve decided to implement a few sample programs in as many languages as possible. Each implementation details a brief history of the language and a description of the code.

The plan for the series is to explore the major general-purpose language like Java, Python, C, C++, and C#. From there, we’ll take a look at some sample programs in web development languages like Ruby, PHP, and JavaScript. As we continue, we’ll cover proprietary languages like Swift and Objective-C. Eventually, we’ll start to tackle less popular languages like Rust, x86, and Verilog. Finally, we’ll play around with some of the esoteric languages like Brainf*ck and LOLCODE.

Who knows? Maybe the Sample Programs in Every Language series will become so popular it’ll never end. To help this series grow, consider sharing it on social media with your friends. Or, if you have a language you want to see, drop your suggestion in the comments.

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Posts