Operating System - HP-UX
1753856 Members
7236 Online
108809 Solutions
New Discussion юеВ

Proper debugging of perl script

 
ROSS HANSON
Regular Advisor

Proper debugging of perl script

Hello,
I have a perl script which requires human intervention. The human needs to give answers to questions asked.
How do I debug a perl script, stepping through it line by line, while answering the question that come up, without it looking as though the answers are debugging commands?
Is there an escape character I can use when an answer is needed?
Ross Hanson
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor

Re: Proper debugging of perl script

Hi Ross:

Interesting. Perhaps this helps. Consider:

# cat /.debugme
#!/usr/bin/perl
use strict;
use warnings;
my ( $count, $name, $title ) = ( 0, undef, undef );
$|++;
print "Enter your name\n";
chomp ( $name = );
print "OK, so you are called '$name'\n";
$count++ for (0..9);
print "count is $count\n";
print "Enter your title\n";
chomp ( $title = );
print "OK, and you are a '$title'\n";
1;

...now do:

# PERLDB_OPTS="NonStop frame=1 AutoTrace" perl -d ./debugme

Regards!

...JRF...
Ralph Grothe
Honored Contributor

Re: Proper debugging of perl script

As already suggested by James,
Perl comes with nice debugger
which among many other things lets you step through your code.

For a quick ref enter the debugger

$ perl -de0

and issue

DB<1> h

or

DB<2> |h h

For more indepth tutorial issue

$ perldoc perldebug

Madness, thy name is system administration