- Toby Inkster
- Pry; Reply
I've never really used the Perl debugger much (maybe I should learn?) and usually resort to lots of
use Data::Dumper; print Dumper($somevar); statements to help me understand what's going wrong with a piece of code.
However, what I often find is that
$somevar contains exactly the data I expected it to contain. So the problem must be another variable? Or maybe there's a function which isn't returning what I expected it to? Or maybe one of my
if statement has jumbled logic? So I need to change my
print Dumper(...) statement and re-run the script.
Anyway, sick of that, and inspired by a question on StackOverflow I've released Pry, a really tiny wrapper around DOY's Reply REPL. Using Pry, you can run your script, and drop into a REPL at the point where you suspect things are going wrong. Once in the REPL you can inspect any lexical variables which are in scope (thanks, PadWalker!), or peek at the call stack (thanks, Devel::StackTrace!); you can even call functions and methods to see what's going on.
So if you, like me, have never managed to figure out breakpoints, and watches, and whatever other thingies a proper debugger has to offer, but are getting frustrated by the limitations of Data::Dumper-based debugging, give Pry a try!