Category Archives: new chapters

Use the C3 method resolution order in multiple inheritance

Perl 5.10 introduced a flexible method resolution order mechanism. Instead of Perl’s default order (see Understand Perl’s default inheritance model), you can try something less stupid by using the mro pragma to specify which order perl. So far, there are only two resolution orders: dfs, which is Perl’s default depth-first search, and c3, a new [...]

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. It’s almost trivial to disprove the [...]

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 [...]

Understand Perl’s default inheritance model

Perl’s default inheritance mechanism is a bit weird, and it’s not something that any language designer would want to repeat. However, it is what it is and by knowing its quirks you should have any easier time tracking down inheritance problems. Before you go further in this Item, though, you have to sit through this [...]

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 [...]

Make your methods know as little as possible

How often have you wished that one of Perl’s modules did things slightly differently? That module mostly works for you except for some hard-coded decisions in string formats, pack specifications, or other minor point that you wish that you could configure. Or, maybe you’ve been the one to write that module. When you have to [...]

Use rational numbers for arbitrary precision

This Item was suggested by Shawn Corey as part of our Free eBook give-away. He’s our September winner! Perl is mostly a platform-agnostic and portable language, but there are a few corners where you notice that Perl isn’t in control of everything. In Item 14: Handle big numbers with bignum, you saw that Perl’s normally [...]

Use formats to create paginated, plaintext reports

Perl’s format feature allows you to easily create line-oriented text reports with pagination, and if that’s what you want, Perl is for you. This item is just an introduction. You can find the full details in perlform, and in future items. You may have never heard of formats, but, believe it or not, they were [...]

Don’t make Perl do more work than it needs to

My choice of algorithms and data organization can lead to orders of magnitude of performance differences between functionally equivalent implementations of my programs. Choosing the right way to do something can save me orders of magnitude in processing. I wrote some code to loop over lines in a file and modify a couple of elements [...]

Implicitly turn on strictures with Perl 5.12

Perl 5.12 can turn on strict for you automatically, stealing a feature from Modern::Perl that takes away one line of boilerplate in your Perl programs and modules. We talk about strict in Item 3: Enable strictures to promote better coding. Similar to what we show in Item 2: Enable new Perl features when you need [...]