Posted by brian d foy on January 31, 2012
Perl’s powerful string manipulation tools include case-shifting operators that change the parts of a double-quoted string. There are many other things that happen in a double-quoted string too, so you need to know where these operators fit in with each other. A double-quoted string has three features: Variable interpolation Escaped and logical characters Case shift [...]
Posted by brian d foy on September 4, 2011
Perl defines two internal pseudo-signals that you can trap. There’s one for die, which I covered in and eventually told you not to use. There’s also one for warn that’s quite safe to use when you need to intercept warnings. To catch a warning, you set a signal handler for the __WARN__ pseudo-signal. The underscores [...]
Posted by brian d foy on May 29, 2011
Perl 5.10 introduced the given-when feature, a fancier version of the C switch feature. However, it was poorly designed and tested and depended on two other dubious features, the lexical $_ and smart-matching. Parts of this feature are salvageable, but you should avoid the literal given (and probably the lexical $_ and the smart matching, [...]
Posted by brian d foy on April 24, 2011
Perl will autovivify complex data structures when you use them as if they already exist. This feature saves you a lot of annoying work defining structures that you intend to use. However, this also means that Perl might create data structures that you don’t intend to use in code that isn’t just assigning values. We [...]
Posted by brian d foy on March 13, 2011
Perl’s eval leads a double life, and, like Dr. Jekyl and Mr. Hyde, one is dangerous and one is almost safe. And, it’s important to know which one is dangerous; I grew up thinking that Dr. Jekyl was the bad one because evil people, such as Dr. No, had titles. You can recognize the evals [...]
Posted by brian d foy on March 6, 2011
There are two major phases in the execution of a program run by Perl, which you sometimes see as “compile time” and “run time”, or sometimes now, “compile phase” and “run phase”. In the broadest of strokes, perl compiles code in the compile phase, and when it’s completely done with that, it moves on to [...]
Posted by brian d foy on February 6, 2011
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 [...]
Posted by brian d foy on January 31, 2011
Once you leave the world of ASCII, things such as string comparisons and sorting get much tougher. In Effective Perl Programming, we devoted a short chapter to Unicode, but there’s a lot more that we could have covered. We mostly ignored the modern idea of locales and Unicode, but those have big effects on how [...]
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 [...]