Home arrow Perl Programming arrow Page 4 - Using The Perl Debugger

A Watchful Eye - Perl

One of Perl's better-kept secrets is its built-in debugger, a powerful utility that allows developers to rapidly track down errors in their Perl scripts. This article introduces you to the Perl debugger, explaining how to use it to step through scripts, set breakpoints, inspect variables and objects, watch expressions and perform stack traces.

TABLE OF CONTENTS:
  1. Using The Perl Debugger
  2. Step By Step
  3. Breaking Free
  4. A Watchful Eye
  5. Acts Of Madness
  6. Test Drive
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 39
June 25, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

You can set a watch-expression (an expression which triggers a halt if its value changes) with the "w" command, as in the following example:


DB<1> w $count
DB<<3>> L
Watch-expressions:
$count

Now that the watch-expression has been set, you can see how it works by writing some code to alter the value of the $count variable. The debugger will display a message every time the variable's value changes.


DB<2> for ($count=0; $count<=10; $count++) { print "Hello!"; };
Watchpoint 0: $count changed:
old value: undef
new value: '0'
DB<<3>> s
main::((eval 13)[/usr/lib/perl5/5.8.0/perl5db.pl:17]:2):
2: for ($count=0; $count<=10; $count++) { print "Hello!"; };;
DB<<3>>
Watchpoint 0: $count changed:
old value: '0'
new value: '1'
main::((eval 13)[/usr/lib/perl5/5.8.0/perl5db.pl:17]:2):
2: for ($count=0; $count<=10; $count++) { print "Hello!"; };;
DB<<3>> Hello!
main::((eval 13)[/usr/lib/perl5/5.8.0/perl5db.pl:17]:2):
2: for ($count=0; $count<=10; $count++) { print "Hello!"; };;
DB<<3>> s
Watchpoint 0: $count changed:
old value: '1'
new value: '2'
for ($count=0; $count<=10; $count++) { print "Hello!"; };

Watch-expressions can be deleted with the "W" command; either specify the expression


DB<<3>> W $count

or delete all currently-set expressions with the * wildcard.


DB<<4>> W *
Deleting all watch expressions ...

Note that adding watch-expressions can result in a performance penalty, so you should try and restrict yourself to not more than three or four at any given time.



 
 
>>> More Perl Programming Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PERL PROGRAMMING ARTICLES

- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: