Perl v5.12 modifies the package
statement to take a version as well as a name. This allows you to implicitly declare the $VERSION
variable: Continue reading “Perl v5.12 adds the package NAME VERSION syntax”
Category: 5.12
The Perl 5.12 yada yada operator
Perl v5.12 adds a placeholder operator, ...
, called the yada yada operator, after an episode of Seinfeld where the interesting parts of the story are replaced with “yada yada yada”. Continue reading “The Perl 5.12 yada yada operator”
Don’t use auto-dereferencing with each or keys
[Update: Perl v5.24 removes this experimental feature, for the reasons I list, among others.]
Perl 5.14 added an auto-dereferencing features to the hash and array operators, and I wrote about those in Use array references with the array operators. I’ve never particularly liked that feature, but I don’t have to like everything. Additionally, Perl 5.12 expanded the job of keys and values to also work on arrays. Continue reading “Don’t use auto-dereferencing with each or keys”
Use Test::More as you experiment
When you’re trying something new, write small programs to test the idea or the new feature. This way, you isolate what you’re doing from the rest of the big application where you might want to use the idea. Some people try to insert the new features directly into the middle of their large programs, but then have problems separating the bugs from the rest of the application with the new thing they want to add. Continue reading “Use Test::More as you experiment”
Use the \N regex character class to get “not a newline”
Perl 5.12 introduced an experimental regex character class to stand in for every character except one, the newline. The \N
character class is everything but the newline.
In prior versions of Perl, this is the same thing as the .
meta character. That is, it’s the same as long as someone doesn’t add the /s
to the match or substitution operator or the regex quoting operator, or doesn’t insert the option inside the pattern: Continue reading “Use the \N regex character class to get “not a newline””
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 easy. This Item shows you how to use the smart match to see if at least one of a series of regexes matches a string. Continue reading “Use a smart match to match several patterns at once”
In Perl v5.12, length(undef) returns undef.
Starting with v5.12, the length of an undefined value is undefined itself. Instead of converting the undef to the empty string then taking the length of that string, v5.12 returns undef: Continue reading “In Perl v5.12, length(undef) returns undef.”
Use when() as a statement modifier
Perl 5.10 introduced the given-when
statement, and Perl 5.12 refines it slightly by letting you use the when
as a statement modifier. A statement modifier puts the conditional expression at the end of the statement (see perlsyn). You’ve probably already used many of these: Continue reading “Use when() as a statement modifier”
Temporarily remove hash keys or array elements with `delete local`
Perl 5.12 adds a feature that lets you locally delete a hash key or array element (refresh your memory of local with Item 43: Know the difference between my
and local
. This new feature allows you to temporarily prune a hash or an array: Continue reading “Temporarily remove hash keys or array elements with `delete local`”
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 them, to turn strictures on automatically, you have to use use with a version of Perl 5.11.0 or later: Continue reading “Implicitly turn on strictures with Perl 5.12”