收集的Perl Debug方法

收集的Perl Debug方法,第1张

概述Perl Debug The concepts of the perl debug are familiar to most programmers. Trace, breakpoint, and conditional breakpoint (watchpoint) are effective means with which to find problems in your perl scri

Perl DeBUG

The concepts of the perl deBUG are familiar to most programmers. Trace,breakpoint,and conditional breakpoint (watchpoint) are effective means with which to find problems in your perl script.

Common errors in perl

Check for these common errors before you try to deBUG a program:

no semi-colon at end of line. matching pairs of delimiters: ( ),{ },[ ]. Using = when you mean ==. Using == when you mean eq. Using == when you mean =~. disagreement of fIEld,array or hash names (remember $data,$data[1],$data{1} and $Data are four different entitIEs. disagreement of subroutine names between execution and deFinition. Incorrect use of if,elsif,else. Not checking your program (and correcting the errors) using the -w switch.

Using the -w switch

perl -w myprogram

Both this useful command and the output from this command are frequently overlooked by experIEnced programmers. I have,on more than one occasion,spent an hour or 2 looking for a problem when correcting the errors displayed on the -w switch would have corrected or led me to the correction of the problem in a couple of minutes.

The deBUG command

perl -d myprogram

Essentially the -d switch allows you to communicate with the perl executable,and allows the perl executable to communicate with you.

StepPing up to the plate

l - Lists the next few lines p [variable name] - lets you print the value of a variable to the command line q - I quit. r - returns from current subroutine If you have written your program as a few subroutines,this is handy for running through each and checking the return. n - executes the next statement at this level Means you don't have to go through those boring subroutine calls. If you don't kNow what I just wrote,get into a program and try it a couple of times. You'll get the hang of it. s - The step command Okay,this is the key for simple deBUGging. Crank up your program in the deBUGger and step through it. If its a small program,this and the r command can take care of most of your needs. By the way,once you enter the s command,just hit enter to repeat the command.

Breaking away

Breakpoints allow you to specify the next stopPing point in a program. For example,lets say I kNow my problems at line 65,I might insert a breakpoint at line 60 and step through the final five lines of code before the problem. You just saved hitting the enter key 60 times.

b - Set a breakpoint

Once you have started the perl deBUGger you may set a breakpoint at any executable line number.

b 20 - Sets a breakpoint at line 20.
b subroutinename - handy little deviation. If you kNow the subroutine name,this breaks on the first line insIDe the routine.
b 20 condition - depending on your background,this is called a conditional breakpoint or watchpoint. Perl breaks when the condition you specify is met.


Examples b 20 x>30 Breaks at line 20 when x is greater than 30 b 20 x=~/foo/i Breaks at line 20 when x contains "foo"

To start the program use c (continue),which runs the program to the first breakpoint or watchpoint.

总结

以上是内存溢出为你收集整理的收集的Perl Debug方法全部内容,希望文章能够帮你解决收集的Perl Debug方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1289235.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存