When Perl made regexes more Unicode aware, starting in v5.6, some of the character class definitions and match modifiers changed. What you expected to match \d
, \s
, or \w
are more expanvise now (Know your character classes under different semantics). Most of us probably didn’t notice because the range of our inputs is limited. Continue reading “Use /aa to get ASCII semantics in regexes, for reals this time”
Category: 5.14
Enforce ASCII semantics when you only want ASCII
When Perl made regexes more Unicode aware, starting in v5.6, some of the character class definitions and match modifiers changed. What you expected to match \d
, \s
, or \w
are more expanvise now (Know your character classes under different semantics). Most of us probably didn’t notice because the range of our inputs is limited. Continue reading “Enforce ASCII semantics when you only want ASCII”
Declare packages outside of their block
Perl v5.14 gets a step closer to a saner way to declare classes with its new package NAME BLOCK
syntax that lets you easily group everything that goes in a package. Continue reading “Declare packages outside of their block”
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”
Set default regular expression modifiers
Are you tired of adding the same modifiers to all of your regular expressions? For instance, if you might always add the /u
modifier to turn on Unicode semantics on all of your patterns, including qr//
, m//
, and s///
. Instead of remembering to do that to every pattern, the re
that ships with Perl 5.14 now lets you do that for all patterns in the current lexical scope. You can also turn off a modifier for the rest of the scope. Continue reading “Set default regular expression modifiers”
Perl 5.14 adds non-destructive transliteration
[This is a mid-week bonus item since it’s so short]
In Perl 5.13.2, you got a non-destructive version of the substitution operator (Use the /r substitution flag to work on a copy). Instead of changing it’s target, the non-destructive version returns a new string that has the substitution. Continue reading “Perl 5.14 adds non-destructive transliteration”
Use array references with the array operators
[Update: Perl v5.24 removes this experimental feature]
There’s a significant change in syntax showing up in Perl 5.14. The array operators push, pop, shift, and unshift previously only worked on named arrays or dereferenced references. Now, thanks to David Golden, they’ll work on array references. Not only that, they’ll work on references that you’ve stored in variables or that come as the return values from subroutine calls. This feature will show up in Perl 5.13.7, so you need to compile a development version to try this: Continue reading “Use array references with the array operators”
Use the return value from srand
[This is another bonus, mid-week item since it’s so short and probably mostly useless as a tweak to what you already do.]
Perl 5.14 changes srand to return the seed that it used to start the pseudorandom number generator that gives you numbers through rand. There are plenty of interwebs that will explain the difference between real randomness and the sort that you get from computers, but for this item, suffice it to say that the numbers you get from perl are completely deterministic. If you start with the same seed, you get the same sequence. Continue reading “Use the return value from srand”
Let perl create your regex stringification
Perl 5.14 changes how regular expression objects stringify. This might not seem like a big deal at first, but it exposes a certain sort of bug that you may have never considered. It even broke several modules on CPAN. If you previously tested for hard-coded stringifications of patterns, Perl 5.14 is probably going to break your code. Continue reading “Let perl create your regex stringification”
Specify any character by its octal ordinal value.
Perl 5.14 gives you some new ways to represent characters so you can avoid some annoying and ambiguous interpolations. Not only that, the new syntax unifies the different ordinal representations so you can specify characters using the same syntax even if you want to use different bases. This feature was added in Perl 5.13.3, in the development branch leading to the next stable version. Continue reading “Specify any character by its octal ordinal value.”