Open Source

Why I Use Perl...and Will Continue to Do So

By Guest Editor Sammy Esmail, February 12, 2013

Despite Perl's steady decline in usage, its users continue their romance with the language's features.

Arrays

The ability to manipulate arrays in Perl is just beautiful. You can dynamically add/remove elements from the end of the array using PUSH/POP, and dynamically move elements into the front of the array using UNSHIFT/SHIFT. Arrays can be indexed positively from the beginning of the array, or with negative indices from the end of the array. Building FIFOs, LIFOs, queues, and stacks is easy. Split and join are two built-in functions that allow for the creation and collapsing of arrays. Splice gives us the power to remove and add elements within the array. Sort and reverse sort allow for sorting in both directions.

Beginning programmers can easily be turned off by Perl's lack of support for multi-dimensional arrays. But the better way to create complex structures including multi-dimensional arrays is to use references (and you cannot fully exploit the power of any language without the use of references).

Smart, High Level Language with Great Built-In Functions

Perl is a high level language. It is a smart language. It simplifies its variable types to scalar, array, and hash.

We never have to worry about variable types. Perl knows when to interpret a value as an integer or a string. The right-hand side knows whether the left-hand operand is asking for an array or single-value. And using "wantarray," you can write your own subroutine modules with similar smartness. And arrays, hashes, and structures can grow and shrink dynamically  Perl takes care of it automagically.

It also supports a large number of great built-in functions. Take a look at the Schwartzian transform to see the power of sorting complex structures using the Map function. And I love the ability to look at a variable and determine whether it is of type $scalar, @array, or %hash by the prefix.

Full Programming Language

Perl is more than a scripting language. It is a general-purpose language. It supports threads and recursion. In one application, I have 16 threads running diagnostics in parallel on a chassis in factory. Perl supports object-oriented programming, and the new Moose library automates and simplifies much of the work. And, finally, GUI support is made possible by using Perl/Tk.

CPAN, Community, and Books

Perl is an open-source language with a strong community. The Perl Comprehensive Perl Archive Network (CPAN) is a repository with more than 25,000 modules. My use of Perl today would be very limited without the ability to use modules like DBI, Excel, Telnet, FTP, Ping, and Win32:Serial Communications to name a few of the modules critical to my field of work.

ActiveState deserves special mention here. For a small fee, you can purchase a compiler that creates a pseudo executable. In deploying applications to remote sites, Active State's PDK allows programmers to compile an application into an executable. Simply drop an executable at one of the numerous factory test stations and you are done. You only need to maintain Perl Libraries at your development workstation. There is no need to worry about loading the latest libraries at every test station.

Other Languages

The aforementioned strengths noted for Perl may well be the strengths of other competing languages. I am not in a position to compare Perl to Python or other similar languages.

The power of Perl as outlined here relates to several domains of work related to data, tools, and automation. My experience is testimony to Perl creator, Larry Wall's statement that Perl is a language for "making simple things easy and difficult things possible." And for that reason, I hope that Mr. Binstock is wrong in his contention that Perl is in a tailspin; it's a wonderful language!

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!