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
Just like normal, I took to Wikipedia to learn more about Perl.
As it turns out, Perl is actually a family of languages sort of like Lisp. 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 Python or C.
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:
However, from my understanding, it’s good Perl style to omit the parentheses for built-in functions.
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 interpreter. 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 Perl from the official website. After that, we should probably get a copy of the solution. Assuming Perl is now in our path, we can get to work:
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.
Python is a fun language to learn on its own, but what if we could learn it by doing something even more fun like making Discord bots?
Are you a little overwhelmed when it comes to writing your first Discord bot? Why not try to make a write-only Discord bot first?