next up previous contents
Next: Summary Up: Logic Errors Previous: Creating Command Aliases

Using the Debugger as an Interactive Interpreter

In the Chapter on Handling Errors and Signals, you learned how to create an interactive Perl interpreter that could replace shell and batch files.

You can also use the debugger as an interactive interpreter. In fact, it does an even better job in some cases.

If you create a script with functions that perform individual system tasks, you can run that script inside the debugger. Then you can call the functions from the debugger command lines as needed. The following listing shows what one possible script might look like.

sub printUserReport {

    # read list of users

    # determine usage statistics

    # display report


sub backupUsers {

    # remove backup file.

    #'delete /user/*.bak'

    # backup user files to tape.

    #'\backup /user/*';


sub help {


    print("backupUsers will perform the nightly backup.\n");

    print("printUserReport will display user usage statistics.\n");




Note This script is really nothing but a skeleton. You should be able to flesh it out with functions that are useful to you.

You load this script into the debugger with the command perl -d After the script loads, you can run any of the functions by typing their name at the debugger prompt. Here is a sample debugger session:

main::(  1;

  DB<1> help

backupUsers will perform the nightly backup

printUserReport will display user usage statistics.

  DB<2> backupUsers

  DB<3> q