2011-02-10 5 views
5

私の目標は、以下のsample.plスクリプトをデバッグ(ステップバイステップ)することです。Perlトレースから変数の値を見るにはどうすればいいですか?

問題:変数($ top_number、$ x、$ total)の実際の値が得られません。

私の質問:トレース出力から($ top_number、$ x、$ total) の実数の値を見るにはどうすればよいですか?

perl -d:Traceで変更する必要がある番号は、$ top_number、$ x、$ totalではありません。トレース出力から

例:

[[email protected] /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? 
. 
. 

[[email protected] /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 $total\n"; 

答えて

7

私はあなたがループを反復ごとに$x$total変数の値を確認したいと仮定します。 Devel::Traceの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; 
+1

わずか数日前に 'Devel :: DumpTrace'がリリースされました。穏やかになり、見つけたバグを報告してください。 :-) – mob

+0

@Mobは心配しないでください – jon

+0

@ hiもう一度エラーが出ます:perl -d:DumpTrace ./sampl.pl @INCにPadWalker.pmが見つかりませんか?なぜ – jon

0

Variable::Magicをご覧ください。それは変数 "トレース"のための解決策かもしれません。

+0

しかし、これは私がperl -dで実行する必要があることを意味しますか?とにかく? – jon

関連する問題