加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何从Perl跟踪中查看变量的值?

发布时间:2020-12-16 06:27:23 所属栏目:大数据 来源:网络整理
导读:我的目标是调试(逐步)下面的sample.pl脚本. 问题:我没有得到变量的实际值($top_number,$x,$total). 我的问题:如何查看($top_number,$total)的实数整数值 从跟踪输出? 需要更改perl -d:Trace以获取数字,而不是:$top_number,$total? 跟踪输出示例: [roo
我的目标是调试(逐步)下面的sample.pl脚本.

问题:我没有得到变量的实际值($top_number,$x,$total).

我的问题:如何查看($top_number,$total)的实数整数值
从跟踪输出?

需要更改perl -d:Trace以获取数字,而不是:$top_number,$total?

跟踪输出示例:

[root@linux /tmp]# perl -d:Trace ./sample.pl 
>> ./sampl.pl:9: $top_number = 100;
>> ./sampl.pl:10: $x = 1;
>> ./sampl.pl:11: $total = 0;
>> ./sampl.pl:12: while ( $x <= $top_number ) {
>> ./sampl.pl:13:       $total = $total + $x;   # short form: $total += $x;
>> ./sampl.pl:14:       $x += 1;                # do you follow this short form?
>> ./sampl.pl:13:       $total = $total + $x;   # short form: $total += $x;
>> ./sampl.pl:14:       $x += 1;                # do you follow this short form?
>> ./sampl.pl:13:       $total = $total + $x;   # short form: $total += $x;
>> ./sampl.pl:14:       $x += 1;                # do you follow this short form?
.
.

[root@linux /tmp]#more sample.pl script

#!/usr/bin/perl 


$top_number = 100;
$x = 1;
$total = 0;
while ( $x <= $top_number ) {
    $total = $total + $x;   # short form: $total += $x;
    $x += 1;                # do you follow this short form?
}

print "The total from 1 to $top_number is $totaln";

解决方法

我假设您希望通过循环查看每次迭代的$x和$total变量的值.来自0700的POD没有迹象表明它可以做到这一点.

但是,Devel::DumpTrace可以.

perl -d:DumpTrace ./sample.pl

>>>>> hw.pl:7:      $top_number:100 = 100;
>>>>> hw.pl:8:      $x:1 = 1;
>>>>> hw.pl:9:      $total:0 = 0;
>>>>> hw.pl:10:     while ( $x:1 <= $top_number:100 ) {
>>>>> hw.pl:11:         $total:1 = $total:0 + $x:1;   # short form: $total:0 += $x:1;
>>>>> hw.pl:12:         $x:2 += 1;                # do you follow this short form?
>>>>> hw.pl:11:         $total:3 = $total:1 + $x:2;   # short form: $total:1 += $x:2;
>>>>> hw.pl:12:         $x:3 += 1;                # do you follow this short form?
>>>>> hw.pl:11:         $total:6 = $total:3 + $x:3;   # short form: $total:3 += $x:3;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读