Logo         Community
  Trog
Services
The Company
Community
Columns
Your Account
Contact Us
 
 
Using The Perl Debugger
Got a Perl problem? Better bring in the debugger.

| Moving Up |

Now that you're in the debugger, let's start with something basic: moving around your script. Type "l" at the command prompt, and watch as the debugger goes busily to work listing the first ten lines of your script.

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
  DB<1> l
6==>    unless($ARGV[0])
7      {
8:              print "ERROR: Please provide a valid input ID\n\n";
9      }
10
11      # get user input into variable
12:    my $id = $ARGV[0];
13
14      # connect
15      # fix these as per your local settings
').'
'

Typing "l" again will take you to the next screen of code,

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
  DB<1> l
16==>  my $dbh = DBI->connect("DBI:mysql:database=db198;host=localhost",
"secret", "", {'RaiseError' => 1}) or die ("Cannot connect to database");
17
18      # set up email message
19:    my $sendmail = "/usr/sbin/sendmail -t";
20:    my $reply_to = "Reply-to: foo\@bar.org";
21:    my $subject  = "Subject: FOOBAR";
22:    my $content = "Hello and how are you doing? This is the message body";
23
24      # now retrieve email addresses and send mail to each
25:    my $sth = $dbh->prepare("SELECT email FROM users WHERE users.id =
'$id'");
').'
'

and so on.

You can have the debugger display a specific line by specifying a line number to the "l" command,

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
  DB<3> l 19
19==>  my $sendmail = "/usr/sbin/sendmail -t";
').'
'

or even display a block of lines by specifying a range of line numbers.

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
  DB<4> l 20-25
20==>  my $reply_to = "Reply-to: foo\@bar.org";
21:    my $subject  = "Subject: FOOBAR";
22:    my $content = "Hello and how are you doing? This is the message body";
23
24      # now retrieve email addresses and send mail to each
25:    my $sth = $dbh->prepare("SELECT email FROM users WHERE users.id =
'$id'");
').'
'

You can display the previous line with the "-" command,

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
  DB<5> -
10==>
11      # get user input into variable
12:    my $id = $ARGV[0];
13
14      # connect
15      # fix these as per your local settings
16:    my $dbh = DBI->connect("DBI:mysql:database=db198;host=localhost",
"root", "secret", {'RaiseError' => 1}) or die ("Cannot connect to database");
17
18      # set up email message
19:    my $sendmail = "/usr/sbin/sendmail -t";
').'
'

or return to the last executed line with the "." command.

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
  DB<5> .
main::(mailer.pl:16):        my $dbh =
DBI->connect("DBI:mysql:database=db198;host=localhost", "root", "secret",
{'RaiseError' => 1}) or die ("Cannot connect to database");
').'
'

You can view the code above and below a specific line with the "v" command,

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
  DB<3> v 27
24:    my $description = $ref->{'description'};
25:    $sth->finish();
26
27      # now use the group ID to get the group text
28:    my $sth = $dbh->prepare("SELECT group_text FROM groups WHERE
group_id =
'$gid'");
29:    $sth->execute();
30:    my $ref = $sth->fetchrow_hashref();
31:    my $gtext = $ref->{'group_text'};
32:    $sth->finish();
33
').'
'

or even perform basic search operations within the debugger.

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
DB<3> /FOOBAR
21:    my $subject  = "Subject: FOOBAR";
').'
'

This ability to move around your script comes in very handy when dealing with large and complex scripts.


How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!


previous page more like this  print this article  next page
 
Search...
 
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
more...
 
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
more...
 
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
more...
 
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
more...
 
In cut!...
American Chai
The Core
Possession
more...
 
Find out how you can use this article on your own Web site!


Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback