Pass the empty subclass test

Is your object-oriented module subclassable? Do you know that from testing or are you just guessing? Setting aside other Perl programmers reaching into your package and redefining your subroutines, there are some basic things you can do to ensure that you’ve made life unhard for the people you want to extend your classes. Continue reading “Pass the empty subclass test”

Use Git::CPAN::Patch to make quick patches to CPAN distributions

The Git distributed version control system is very popular in with Perlers, and even if you aren’t using it for your own project, you should know how to do simple things with it so you can interact with the most active parts of the community. It’s not that hard. Not only that, many Perl projects are on Github, and it’s something else you’ll know when you go to your next interview. Continue reading “Use Git::CPAN::Patch to make quick patches to CPAN distributions”

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. Continue reading “Understand autovivification”

Use DateTime to disprove internet calendar memes

There’s a popular internet meme that says a July will only ever have five complete weekends, a Friday-Saturday-Sunday triplet, only every 823 years. To programmers, that might seem just absurd, but a lot of people believe it without thinking about it: that’s how it becomes the popular internet meme. Continue reading “Use DateTime to disprove internet calendar memes”

Use the > and < pack modifiers to specify the architecture

Byte-order modifiers are one of the Perl 5.10 features farther along in perl5100delta, after the really big features. To any pack format, you can append a < or a > to specify that the format is little-endian or big-endian, respectively. This allows you to handle endianness in the formats that don’t have specify versions for each architecture already, as well as apply endianness to groups. Continue reading “Use the > and < pack modifiers to specify the architecture"

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 by their first, and only, argument. One form takes a string and the other takes a block. The string version compiles a string as Perl code and executes its, all at runtime. The block form runs, at run time, code that perl has already compiled. Continue reading “Know the two different forms of eval”

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 the run phase, where it executes the code that it completely compiled. Continue reading “Know the phases of a Perl program’s execution”