Posted by brian d foy on November 20, 2011
You can write your own mini (or micro) debuggers to watch your program run. You might want to do this when the other Perl debuggers are too heavyweight (or even too interactive) for your immediate problem. The Devel::Trace module is a simple debugging tool that lets you watch the flow of control as your program [...]
Posted by brian d foy on November 13, 2011
You can use several different Perl modules to inspect data structures. Many of these modules, however, are really two tools in one. Besides showing a data structure as a string, they also serialize the data as Perl code so you can reconstruct the data structure. That second job often makes things hard for you. If [...]
Posted by brian d foy on October 23, 2011
Profile before you decide where to optimize—you might be surprised where you’re losing all of your performance. We won’t go into all the details of profiling in this Item, but you can read about those in Mastering Perl. In short, profilers count something then report the results. They can track any of the things that [...]
Posted by brian d foy on October 2, 2011
Programmers generally consider two types of error communication: the “modern” and shiny exception throwing, and the old and decrepit return values. When they consider these, they choose one and forsake the other. One is good, and the other is bad. Programmers won’t agree on which is which though. The return value technique comes from older [...]
Posted by brian d foy on September 18, 2011
When you’re using code references heavily, you’re going to have a problem figuring out which one of them is having a problem. You define them in possibly several and far-flung parts of your program, but when it comes to using them, you don’t know which one you are using. You can’t really print its value [...]
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 July 24, 2011
If you need to deal with XML, first, we’re very sorry. Maybe you did something wrong if a previous life, such as munging XML with regular expressions. If you do better in this life, perhaps you won’t have to deal with XML in the next one. That right thing might be using XML::Twig, a powerful [...]
Posted by brian d foy on July 3, 2011
Perl 5.16 makes the Perl special variable, $$, writeable, but with some magic. That’s the variable that holds the process ID. Why would you ever want to do that? There’s not much to write about with this new feature, but there’s plenty to write against it since it introduces more magic (see commit 9cdac2 on [...]
Posted by brian d foy on May 22, 2011
Perl lets you override the effects of warn and die by redefining the signals that Perl sends when you call those functions. You probably don’t want to use the signal from die, though, since it might mean a couple of different things. You handle these special signals by setting values in the %SIG hash just [...]
Posted by brian d foy on May 8, 2011
Is your object-oriented module subclassable? Do you know that from testing or are you just guessing? Setting aside other Perl programmers reaching into your package and redefining your subroutines, there are some basic things you can do to ensure that you’ve made life unhard for the people you want to extend your classes. If you [...]