2011-02-10 8 views
5

मेरा लक्ष्य नीचे sample.pl स्क्रिप्ट डीबग (चरण-दर-चरण) है।मैं पर्ल ट्रेस से चर के मान कैसे देख सकता हूं?

समस्या: मुझे चर के वास्तविक मूल्य ($ top_number, $ x, $ कुल) नहीं मिलते हैं।

मेरा प्रश्न: ट्रेस आउटपुट से के वास्तविक पूर्णांक मानों को कैसे देखें?

संख्या प्राप्त करने के लिए perl -d:Trace में बदलने की क्या ज़रूरत है, और नहीं: $ top_number, $ x, $ कुल? ट्रेस उत्पादन से

उदाहरण:

[[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 के लिए पीओडी से कोई संकेत नहीं है कि यह ऐसा कर सकता है।

हालांकि, 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

'डेवेल :: डंपट्रेस' कुछ दिन पहले जारी किया गया था। सभ्य रहें और आपको मिलने वाली किसी भी बग की रिपोर्ट करें। :-) – mob

+0

@Mob चिंता न करें मैं – jon

+0

@ हाय फिर से मुझे त्रुटि मिल जाएगी: perl -d: DumpTrace ./sampl.pl @INC में PadWalker.pm का पता नहीं लगा सकता? क्यों – jon

0

Variable::Magic पर एक नज़र डालें। यह परिवर्तनीय "ट्रेसिंग" के लिए एक समाधान हो सकता है।

+0

लेकिन इसका मतलब है कि मुझे perl -d के साथ चलाने की आवश्यकता है? वैसे भी? – jon

संबंधित मुद्दे