Perl
In short
Perl is a mature, dynamic scripting language famous for text processing and built-in regular expressions, long used for system administration and web scripts.
What is Perl?
Perl is a general-purpose scripting language created by Larry Wall and first released in 1987 to make report processing and text manipulation easier on Unix systems. The name is often expanded as "Practical Extraction and Report Language", though that expansion was coined after the name. Perl 5 is what most people mean by Perl today; the project once called Perl 6 grew into a separate language and was renamed Raku in 2019.
Perl is dynamically typed and uses sigils, symbols in front of variable names, to show what kind of data they hold: $ for a single value, @ for an array and % for a hash (a dictionary). Regular expressions are built into the syntax rather than added through a library, which makes searching, extracting and rewriting text very concise. Its motto, "there's more than one way to do it", reflects a flexible design, and CPAN, the Comprehensive Perl Archive Network, has hosted reusable modules since 1995.
Perl was nicknamed the "duct tape of the internet" in the 1990s, when it powered many early dynamic websites through CGI scripts. Today it is used for system administration, log and text processing, bioinformatics and maintaining large existing codebases, and it comes preinstalled on many Linux and Unix systems. Its regex syntax was so influential that the PCRE library, short for Perl Compatible Regular Expressions, is used by many other languages and tools.
Perl is often compared with Python and Ruby, which took over many of its scripting roles. Ruby was directly influenced by Perl and shares its expressive, flexible style, while Python deliberately chose a stricter "one obvious way" philosophy that many find easier to read in large programs. Perl's compact syntax is powerful for one-off text tasks but can be hard to read later, which is why it is sometimes jokingly called a "write-only" language.
Key takeaways
- Perl is a dynamic scripting language built for text processing.
- Regular expressions are part of the core syntax.
- Sigils like
$,@and%mark scalars, arrays and hashes. - CPAN provides a large archive of reusable Perl modules.
- Perl 6 was renamed Raku and is a separate language from Perl 5.
Example
#!/usr/bin/perl
use strict;
use warnings;
# Count HTTP status codes in a web server log read from standard input
my %count;
while (my $line = <STDIN>) {
$count{$1}++ if $line =~ /" (\d{3}) /;
}
for my $status (sort keys %count) {
print "$status: $count{$status}\n";
}Readers ask
Is Perl still used?
Yes, though less often for new projects than in the 1990s and 2000s. Perl 5 is still actively maintained, ships with many Unix-like systems and runs a large amount of existing system administration, text processing and web code.
What is the difference between Perl and Raku?
Raku began as Perl 6, a redesign of the language, but grew so different that it was renamed in 2019. Perl 5 continues as Perl, and the two are separate languages with separate communities.
Why is Perl good for text processing?
Regular expressions, string operators and file handling are built directly into the language, so tasks like filtering logs or rewriting files often take only a few lines. Command-line flags also let you run Perl one-liners straight from the shell.
See also
- Regular ExpressionProgramming Fundamentals, p. 49A regular expression, or regex, is a pattern written in a compact syntax that describes text to search for, validate, extract or replace within strings.
- RubyProgramming Languages, p. 28Ruby is a dynamic, object-oriented programming language designed for developer happiness, best known for readable syntax and the Ruby on Rails web framework.
- PythonProgramming Languages, p. 26Python is a general-purpose, dynamically typed programming language known for readable syntax and wide use in data science, automation, and web backends.
- LinuxDevOps & Cloud, p. 33Linux is an open-source operating system kernel that powers most servers, cloud platforms, containers, and Android phones, usually packaged as a distribution.
- ShellOperating Systems, p. 27A shell is a program that reads commands typed by a user or written in a script and asks the operating system to run them, usually through a text interface.
- PHPProgramming Languages, p. 23PHP is a dynamically typed scripting language designed for web development that runs on the server to generate HTML pages and respond to browser requests.
Spotted a mistake or something missing on this page?Suggest an edit