The conditional (ternary) operator
One way to reduce the verbosity of Perl code is to replace if-else statements with a conditional operator expression. The conditional operator (aka ternary operator) takes the form: logical test ? value if true : value if false.
Read it
Perl for loops
Perl’s for loops are a powerful feature that, like the rest of Perl can be as concise, flexible and versatile required. This article covers the core features for Perl’s for loops.
Read it
Test if the user is root
When Perl is executing a program, it maintains the user id of the process owner in a global variable ($<). When a Perl program is executed by root or a user with root privileges (e.g. using the sudo command), the user id variable is always set to zero. This can be checked at the command line:
Read it
List shortcuts: qw the quote whitespace operator
A popular way to build a list of literal quotes in Perl is to use the quote whitespace operator (qw). It’s terse, versatile and elegant. To see why, let’s look at a typical statement using a list of strings:
Read it
List all Perl modules installed via CPAN
A quick way to list all non-core modules installed via CPAN using the command line:
Read it
Modern Perl mecca: modernperlbooks.com
Although not precisely defined, Modern Perl programming refers to the use of best practice coding syntax, environment configuration tools, new Perl modules and the general joie de vivre associated with Perl since version 5.10.2. During this time the Perl language and available modules went through an upgrade of several tons of awesome, which resulted in a more concise, idiomatic syntax, and powerful new tools including web frameworks, ORMs and configuration managers.
Read it
Perl arrays 101 - create, loop and manipulate
Arrays in Perl contain an ordered list of values that can be accessed using built-in functions. They are one of the most useful data structures and frequently used in Perl programming.
Read it
Upgrade your list printing using field separator variables
A typical way to print every element of an array in Perl is using a foreach loop:
Read it
Repeat strings with the repetition operator Repeat strings with the repetition operator
You get the idea - Perl has a repetition operator (x) that repeats the scalar or list on its left by the number on it’s right (like multiplication).
Read it
Check your module POD using perldoc
Perl ships with a command-line program called perldoc that makes it easier to search and read Perl’s vast documentation in the POD markup language. If perldoc is called with the -F flag, it will display the POD markup of an input file - this can be useful when your are developing a new Perl distribution and want to check the appearance of the POD in your module before it appears on CPAN for all to see.
Read it
Perl string functions - concatenate substring and split
Perl has many string functions, let’s take a look at a some of the most common ones: concatenate, substring and split.
Read it
Quoting strings in Perl - even ones containing apostrophes and quote or speech marks
Broadly speaking Perl has two types of strings: quotes that are interpolated at runtime and literal quotes that are not interpolated. Let’s review each of these in turn.
Read it
Find the index of the last element in an array
Most Perl programmers know that to find the size of an array, the array must called in a scalar context like this:
Read it
3 quick ways to find out the version number of an installed Perl module from the terminal
Perl module features and behaviour can change from version to version and so knowing the version number of an installed Perl module can be useful in several scenarios. Below are three different command line methods for finding out the version number of an installed module that work on Bash and Windows Powershell. So fire up the terminal and get typing!