這個Perl 神器是一個CPAN模塊瞧挤,顧名思義薄霜,它是一個智能的注釋模塊。下面看CPAN中它的自我介紹:
Smart comments provide an easy way to insert debugging and tracking code into a program. They can report the value of a variable, track the progress of a loop, and verify that particular assertions are true.
1.直觀的一瞥
首先我們先來體驗一下這個模塊的功能:
您也可以看愛程序網(wǎng) 這里的介紹:
貌似 xshalk 的博客也有。
首先寫如下程序:
$ vim test.smart_comments.pl
use strict;use warnings;
use Smart::Comments;
for my $value( 1 .. 3 ){
my $result = $value + 4;
### $result
}
我們來看運行結(jié)果:
$perl test.smart_comments.pl
### $result: 5
### $result: 6
### $result: 7
如果關(guān)掉 Smart::Commets, 那么就沒有輸出結(jié)果!
從上面可以看到這個模塊的功能炕檩!
2. 記載常用的命令,以供以后使用
- 查看變量與輸出程序執(zhí)行信息:
### EXPRESSION
### TEXT...
### [<now>] Acquiring data...
### Acquiring data at <loc>...
[<now>] 將會輸出 程序執(zhí)行的時間捌斧!
\2. 顯示進度條(Progress Bars)
for (@candidates) { ### Evaluating [===| ] % done
將會顯示:
Evaluating [| ] 0% done
Evaluating [===| ] 25% done
Evaluating [========| ] 50% done
Evaluating [============| ] 75% done
Evaluating [=================] 100% done
\3. 檢查斷言(Checks and Assertions via Comments) 笛质?
### require: BOOLEAN_EXPR.
### require: $min < $result && $result < $max
if the expression evaluated false, the comment would die with the following message:
### $min < $result && $result < $max was not true at demo.pl line 86.
### $min was: 7
### $result was: 1000004
### $max was: 99