Browse Definitions :
Definition

Perl

What is Perl?

Perl is a family of script programming languages that is similar in syntax to the C language. It is an older, open source, general use, interpreted language.

Perl was developed with usability in mind. Its efficient design lets developers do a lot with a little bit of code. Its nickname is the "Swiss Army chainsaw" of the internet.

Perl is simpler to learn and code with than more structured languages, such as C and C++. Nevertheless, the language is used to develop advanced programs. The language is often used to develop common gateway interface (CGI) programs because it has good text manipulation capabilities and the ability to deal with binary files.

Design and features of Perl

Perl includes popular Unix facilities, such as sed, awk and tr. As an interpreted language, code can run as is, and instructions are executed without first compiling the entire program into machine language instructions.

However, Perl can be compiled before execution into C code or cross-platform bytecode. When compiled, a Perl program is almost as fast as a fully pre-compiled C language program. A plugin is available for some servers, such as Apache, loading Perl permanently in memory. This reduces compile time and results in faster execution time of CGI Perl script.

Here are additional Perl features:

  • Glue language. As a glue code language, Perl makes it easier for programmers to integrate otherwise incompatible interfaces and components. It features a database integration interface that supports third-party databases, like MySQL, Oracle, Postgres and Sybase.
  • Embedding. Perl can be embedded in database servers and web servers.
  • Text processing. It includes powerful text processing tools that enable it to work with markup languages, like Hypertext Markup Language and Extensible Markup Language.

Perl syntax and code examples

Like all programming languages, Perl follows a basic syntax for writing code. It contains keywords and variables for storing expressions and statements that execute the program's logic.

A Perl program always begins with this line of code:

#!/usr/bin/perl

This is the shebang line. It lets the computer know that the following text will be Perl code and calls the Perl interpreter. Perl programs must pass through the interpreter to execute.

After that, a user could write a basic "Hi there, world!" script:

print "Hi there, world!\n"

The output would be the following:

"Hi there, world!"

Users could also declare a variable. In Perl, the variable is predefined by a variable indicator -- a $, @ or %. These define the data type:

  • Scalar data types, which store numbers, strings and references, are preceded by $.
  • Arrays, which store ordered lists of scalars, are preceded by @.
  • Hashes, which store sets of Key-value pairs, are preceded by %.

To declare a simple string, which is a scalar data type, $ should be used:

$str = "My name is Sam";
print "$str\n"

Here, the output would be the following:

"My name is Sam"

Perl also has many special variables, which are denoted by altering the normal variable indicators, as shown in this list.

An example of a more advanced program from Perl.org is below. This program sends an email using Perl script:

#!/usr/bin/perl
use strict;
use warnings;
# create the email message
use Email::MIME;
my $note = Email::MIME->create(
  header_str => [
    From    => '[email protected]',
    To      => '[email protected]',
    Subject => 'Happy New Year!',
  ],
  attributes => {
    encoding => 'quoted-printable',
    charset  => 'ISO-8859-1',
  },
  body_str => "Wishing you a very happy New Year!\n",
);
# send the email
use Email::Sender::Simple qw(sendmail);
sendmail($note);

Pros and cons of using Perl

Perl has several advantages, as well as some disadvantages.

Advantages

Perl's advantages include the following:

  • Options. Users have a lot of alternatives in how they write a program or solve a problem using Perl.
  • Flexible. The language's design and syntax let users code using their own programming style.
  • Open source. Perl is free for anyone to access, develop and use on a variety of platforms.
  • Availability. It is pre-installed in many places, and more than 25,000 Perl modules are available on the Comprehensive Perl Archive Network. It is also implemented on most operating systems.

Disadvantages

Perl's major disadvantage is that it's a relatively messy language in a number of ways:

  • Hard to read. Some developers claim Perl is difficult to read and less streamlined than newer languages, like Python. Because there many ways to write a Perl program, it can lead to disorganized, untidy code.
  • Difficult to debug. Because Perl code can be obscure or messy, debugging and fixing problems can be difficult.
  • Performance flaws. The same flexibility that benefits Perl users can also cause it to be slow. That's because this flexibility can lead to inefficiencies and redundancy taking it longer to compile.

Perl vs. Python

Perl and Python have a shared history. Both were invented to simplify scripting. Perl was developed to give a C-like structure to Unix scripts. Python was invented to make C simpler and ready to script with.

Perl and Python are similar syntactically, and translating from Perl to Python is relatively easy with a few major syntax changes.

However, here are four key differences:

  1. Lines written in Perl end in a semicolon.
  2. Perl contains curly braces and indentation; Python does not.
  3. Variable names in Perl are styled using a variable indicator, like $x, %x and x. Variable names in Python are styled without a variable indicator, like x.
  4. The print statement in Python adds a new line at the end of output.
Perl vs. Python code example
These code examples show the syntactical differences between Python and Perl. One of the most notable is the use of $ to indicate the data type of a variable.

Other differences include the following:

  • Perl can be messy, and Python is more streamlined.
  • There are many ways to do things in Perl, whereas Python is designed to provide one clear path to any given function.
  • Python is easier to read than Perl.
  • Python is considered one of the best coding languages to learn and one of the easiest for novice developers.
  • Python is a newer language than Perl.
  • Perl is integrated with web application source code.
  • Python has a reputation as a dynamic programming language with a broad array of applications -- from web development to machine learning -- making it a popular language.
  • The open source developer community is more supportive of Python.

History and future of Perl

Programmer Larry Wall created the first version of Perl in 1987. Perl was originally said to stand for "Practical Extraction and Reporting Language," but that name is no longer used. Wall prefers to use "Perl" for the language itself and "perl" for any interpreter or compiler of the language.

Perl 5 first became available in 1994. The latest stable version of Perl is 5.34.0, according to Perl.org.

Perl 6 is rooted in the same ancestor language as Perl 5 but is a separate programming language. It has its own design team of open source volunteers.

The Perl 6 project began after the 2000 Perl Conference, but the first official version of the language, version 6.c, wasn't available until December 2015. Perl 6 was renamed Raku in 2019.

Today, Perl refers to Perl 5. Work on Perl 7 began in 2020. It is expected to be available in 2021.

Learn more about Perl and four other programming languages that are still influential but are likely to be obsolete in the next decade.

This was last updated in November 2021

Continue Reading About Perl

Networking
  • SD-WAN security

    SD-WAN security refers to the practices, protocols and technologies protecting data and resources transmitted across ...

  • net neutrality

    Net neutrality is the concept of an open, equal internet for everyone, regardless of content consumed or the device, application ...

  • network scanning

    Network scanning is a procedure for identifying active devices on a network by employing a feature or features in the network ...

Security
  • virtual firewall

    A virtual firewall is a firewall device or service that provides network traffic filtering and monitoring for virtual machines (...

  • cloud penetration testing

    Cloud penetration testing is a tactic an organization uses to assess its cloud security effectiveness by attempting to evade its ...

  • cloud workload protection platform (CWPP)

    A cloud workload protection platform (CWPP) is a security tool designed to protect workloads that run on premises, in the cloud ...

CIO
  • Regulation SCI (Regulation Systems Compliance and Integrity)

    Regulation SCI (Regulation Systems Compliance and Integrity) is a set of rules adopted by the U.S. Securities and Exchange ...

  • strategic management

    Strategic management is the ongoing planning, monitoring, analysis and assessment of all necessities an organization needs to ...

  • IT budget

    IT budget is the amount of money spent on an organization's information technology systems and services. It includes compensation...

HRSoftware
  • ADP Mobile Solutions

    ADP Mobile Solutions is a self-service mobile app that enables employees to access work records such as pay, schedules, timecards...

  • director of employee engagement

    Director of employee engagement is one of the job titles for a human resources (HR) manager who is responsible for an ...

  • digital HR

    Digital HR is the digital transformation of HR services and processes through the use of social, mobile, analytics and cloud (...

Customer Experience
  • chatbot

    A chatbot is a software or computer program that simulates human conversation or "chatter" through text or voice interactions.

  • martech (marketing technology)

    Martech (marketing technology) refers to the integration of software tools, platforms, and applications designed to streamline ...

  • transactional marketing

    Transactional marketing is a business strategy that focuses on single, point-of-sale transactions.

Close