Category Archives: 5.10

Define grammars in regular expressions

[ This is the 100th Item we've shared with you in the two years this blog has been around. We deserve a holiday and we're taking it, so read us next year! Happy Holidays.] Perl 5.10 added rudimentary grammar support in its regular expressions. You could define many subpatterns directly in your pattern, use them [...]

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

Use a smart match to match several patterns at once

The smart match operator (Item 23. Make work easier with smart matching) reduces many common comparisons to a few keystrokes, keeping with Perl’s goal of making the common things easy. You can use the smart match operator to make even less common tasks, such as matching many regular expressions at the same time, just as [...]

Set default values with the defined-or operator.

[This is a mid-week bonus Item since it's so short] Prior to Perl 5.10, you had to be a bit careful checking a Perl variable before you set a default value. An uninitialized value and a defined but false value both acted the same in the logical || short-circuit operator. The Perl idiom to set [...]

Use branch reset grouping to number captures in alternations

Perl’s regular expressions have a simple rule for capturing groups. It counts the order of left parentheses to assign capture variables. Not all capture groups must actually match parts of the string, and Perl doesn’t care if they do. Perl assigns capture groups inside an alternation consecutively, even though it knows that only one branch [...]

Watch out for side effects with `use VERSION`

To specify that you wanted to use at least a particular version of Perl, you specified that version with the use built-in: use VERSION; We covered this in Item 83: Limit your distributions to the right platforms, and we mentioned that it might invoke side effects. We didn’t get into the details in that Item [...]

Perl 5.10 new features

Perl 5.10 introduced many new features that had built up over the years. Some of these we covered in the book, but we’ll cover some of those that we neglected. It might take us some time to get around to them all, but we’ll eventually make it. If you want to read about some sooner [...]