Is there a way to turn on tracing in perl (equivalent to bash -x)?

前端 未结 4 1446
滥情空心
滥情空心 2020-12-30 18:54

I have a system script in perl. I need some equivalent of bash -x to determine what is going wrong with the script. Is there something equivalent?

EDIT: What bash -x

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 19:54

    Take a look at Devel::Trace or Devel::ebug.

    Given this program named w.pl:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    my $answer = 42;
    
    if ($answer == 6 * 9) {
        print "everything is running fine.\n";
    } else {
        warn "there must be a bug somewhere...\n";
    }
    

    You can use Devel::Trace to watch the execution:

    perl -d:Trace w.pl
    

    Which produces the following output:

    >> w.pl:6: my $answer = 42;
    >> w.pl:8: if ($answer == 6 * 9) {
    >> w.pl:11:     warn "there must be a bug somewhere...\n";
    there must be a bug somewhere...
    

提交回复
热议问题