Category Archives: The Basics of Perl

Deprecation warnings now tell you when the features will disappear

Perl v5.28 will have better deprecation warnings. Most of this I picked up from the lightning talk that Abigail gave at The Perl Conference. Perl 5, released in 1994, deprecated many things that it never removed. It’s over 20 years later and those things are still there. Even though they are deprecated they had no […]

Perl v5.22 adds hexadecimal floating point literals

You can specify literal hexadecimal floating-point numbers in v5.22, just as you can in C99, Java, Ruby, and other languages do. Perl, which uses doubles to store floating-point numbers, can represent a limited set of values. Up to now, you’ve had to specify those floating point numbers in decimal, hoping that a double could exactly […]

Perl 5.20 introduces “Key/Value Slices”

Perl v5.20 adds the “Key/Value Slice”, which extracts multiple keys and their corresponding values from a container (hash or array). It uses the %, which is new, legal syntax for a variable name with subscripts after it:

Understand the order of operations in double quoted contexts

Perl’s powerful string manipulation tools include case-shifting operators that change the parts of a double-quoted string. There are many other things that happen in a double-quoted string too, so you need to know where these operators fit in with each other. A double-quoted string has three features: Variable interpolation Escaped and logical characters Case shift […]

Intercept warnings with a __WARN__ handler

Perl defines two internal pseudo-signals that you can trap. There’s one for die, which I covered in and eventually told you not to use. There’s also one for warn that’s quite safe to use when you need to intercept warnings. To catch a warning, you set a signal handler for the __WARN__ pseudo-signal. The underscores […]

Use for() instead of given()

Perl 5.10 introduced the given-when feature, a fancier version of the C switch feature. However, it was poorly designed and tested and depended on two other dubious features, the lexical $_ and smart-matching. Parts of this feature are salvageable, but you should avoid the literal given (and probably the lexical $_ and the smart matching, […]

Understand autovivification

Perl will autovivify complex data structures when you use them as if they already exist. This feature saves you a lot of annoying work defining structures that you intend to use. However, this also means that Perl might create data structures that you don’t intend to use in code that isn’t just assigning values. We […]

Know the two different forms of eval

Perl’s eval leads a double life, and, like Dr. Jekyl and Mr. Hyde, one is dangerous and one is almost safe. And, it’s important to know which one is dangerous; I grew up thinking that Dr. Jekyl was the bad one because evil people, such as Dr. No, had titles. You can recognize the evals […]

Know the phases of a Perl program’s execution

There are two major phases in the execution of a program run by Perl, which you sometimes see as “compile time” and “run time”, or sometimes now, “compile phase” and “run phase”. In the broadest of strokes, perl compiles code in the compile phase, and when it’s completely done with that, it moves on to […]

Use Data::Dump filters for nicer pretty-printing

Data::Dumper, a module that comes in the Standard Library, is one of the great tools knows to Perlers. You give it a big data structure and it pretty prints it for you. If you are one of those people who still believe that the best debugger in the world is print and need to get […]