How can I debug a Perl script?

前端 未结 8 1508
天涯浪人
天涯浪人 2021-02-01 16:47

When I run a Perl script, how can I debug it? For example, in ksh I add the -x flag. But how I do the same in Perl?

8条回答
  •  萌比男神i
    2021-02-01 17:07

    To run your script under the Perl debugger you should use the -d switch:

    perl -d script.pl
    

    But Perl is flexible. It supplies some hooks, and you may force the debugger to work as you want

    So to use different debuggers you may do:

    perl -d:DebugHooks::Terminal script.pl
    # OR
    perl -d:Trepan script.pl
    

    Look these modules here and here.

    There are several most interesting Perl modules that hook into Perl debugger internals: Devel::NYTProf and Devel::Cover

    And many others.

提交回复
热议问题