Posted by brian d foy on February 27, 2011
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 [...]
Posted by brian d foy on January 9, 2011
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 [...]
Posted by brian d foy on December 26, 2010
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 [...]
Posted by brian d foy on December 22, 2010
[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. Perl 5.13.7 extends the /r to work [...]
Posted by brian d foy on November 6, 2010
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 [...]
Posted by brian d foy on October 28, 2010
[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 [...]
Posted by brian d foy on October 25, 2010
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 [...]
Posted by brian d foy on October 13, 2010
[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 [...]
Posted by brian d foy on October 11, 2010
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 [...]
Posted by brian d foy on October 3, 2010
Perl 5.14, when it’s released, allows you to use a return value from given-when. You have to wrap it in a do (Item 25: Use do {} to create inline subroutines): use 5.013; my $value = do { given ( $ARGV[0] ) { when( /^\p{N}+\z/ ) { ‘digits’ } when( /^\p{L}+\z/ ) { ‘alphabetics’ } [...]