Perl hash basics: create, update, loop, delete and sort
Hashes are one of Perl’s core data types. This article describes the main functions and syntax rules for for working with hashes in Perl.
Hashes are one of Perl’s core data types. This article describes the main functions and syntax rules for for working with hashes in Perl.
If you need to write object oriented Perl code with no dependencies, then you need to use the old school Perl syntax. This article describes the main features of old school object oriented Perl including class declaration, constructors, destructors, methods, attributes, accessors and inheritance.
Perl is remarkably flexible and allows you to achieve all kinds of wizardry with the language. One example of this is using a dereferencing block to use a scalar value as a variable name. This allows you to use variables with dynamic names.
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.
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.
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:
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:
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.
A typical way to print every element of an array in Perl is using a foreach loop:
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).
Perl has many string functions, let’s take a look at a some of the most common ones: concatenate, substring and split.
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.
Most Perl programmers know that to find the size of an array, the array must called in a scalar context like this:
Many practical programming problems require you to parse data. Ron Savage continues his demonstration of Marpa and other tools and techniques for lexing and parsing data. Put down the regexps; get it right this time.
Perl programmers spend a lot of time reading, modifying, and writing data. When regular expressions aren’t enough, turn to something more powerful: parsing.
Perl 5.14 provides a new feature called unicode_strings to improve Unicode string handling.