Can I insert break point into source perl program?

前端 未结 4 1227
臣服心动
臣服心动 2021-02-12 20:00

I want the perl program launch debugger when some condition hit. Some other language has debug() statement supported by library, is there any similar statement in perl?

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-12 21:01

    Have you tried adding the -d switch to the shebang line at the top of your script? Something like

    #!/usr/bin/perl -d
    use strict;
    use warnings;
    $|=1;$\="\n";
    
    print "Test";
    

    It really depends exactly how it gets launched, but at least in simple cases this should start the debugger.

    Edit: You can then set a breakpoint on a specific line with a certain condition using

    > b [line] [condition]
    

    and hit

    > c
    

    to continue with running the script - the debugger will stop at the specified line when the condition is met

提交回复
热议问题