What is Perl and where it runs

What Perl is

Perl is an interpreted language created by Larry Wall in 1987. You write plain text, and the perl program runs it line by line with no compile step in between.

Perl was born as a report-processing tool on Unix, so text is its home ground: regular expressions are part of the syntax, not a library that you import. Files, pipes, processes and environment variables are equally close at hand.

print "Hello from Perl\n"; print 2 + 2, "\n"; # prints 4

perl demo.pl

Hello from Perl
4

Where Perl runs

Perl runs on Linux, UNIX systems such as FreeBSD, macOS, and Windows through the Strawberry Perl distribution. One script usually travels between them without changes, because the language and the standard library are the same everywhere.

Ask the interpreter which version is active. The answer is printed by the language itself, so it is the first sentence of any Perl debugging session:

print "$^V\n"; # prints something like v5.42.2

perl demo.pl

v5.42.2

Why learn Perl

Perl is the shortest path from a messy log file to a clean report. A one-line command can filter, transform and count millions of lines, which is why the language still runs inside build systems, mail filters and monitoring setups.

Learning it also pays off in maintenance work. Plenty of production code written between 1995 and 2010 is Perl, and someone has to read it. The habits you gain - regular expressions, testing, careful file handling - transfer to Python, Ruby and PHP.

my @words = qw(perl text report); print scalar @words, " words\n"; # prints 3 words

perl demo.pl

3 words

Three virtues

Wall named three programmer virtues: laziness, impatience and hubris. Laziness makes you write reusable tools instead of repeating work, impatience makes those tools fast to run, and hubris makes you write code that others can read without shame.

The same culture produced the famous motto there is more than one way to do it. Many problems have several idiomatic solutions, and the course shows the one that reads best, not the cleverest one.

my %seen = (); $seen{$_}++ for qw(a b a); print "$seen{a}\n"; # prints 2

perl demo.pl

2

Next: Install Perl and check the version

Article author: Arthur Isaev

Banner image