Thursday, May 6, 2010

perl trace; a very useful debug utility

I was given a perl script and asked to fix the code where a particular option was not behaving as expected. The code was huge.
What's the best/faster way to locate the problem ?

Obviously I had to use a debugger; just like any other programming language perl too has it's own debbuger.
By giving perl the -d switch at command line will invoke the perl debugger.
The best option to understand the code flow and reach to the problematic option is enable trace while debugging.
perl help describes trace like this :
t [expr] Toggle trace [trace expr]

Once you enable trace; all the statements executed along with their line numbers will be displayed on the screen. It is similar to viewing code flow in a shell script by using a "-x" switch.
It is much better than using step/next not knowing where it is leading to and when it will end. So, get an overview of the code flow with t(trace) and make debugging easier.

No comments:

Post a Comment