perl模块之Smart::Comments

perl模块之Smart::Comments,第1张

概述这个模块用注释的方式调试和跟踪代码,写好了之后把use Smart::Comments去掉就可以了。 实验 最后上代码实验大部分特性: [root@localhost Smart::Comments]# cat 1.pl #!/usr/bin/env perl use strict; use Smart::Comments; my $date = "2014-

这个模块用注释的方式调试和跟踪代码,写好了之后把use Smart::Comments去掉就可以了。

实验

最后上代码实验大部分特性:

[root@localhost Smart::Comments]# cat 1.pl     #!/usr/bin/env perl    use strict;    use Smart::Comments;    my $date = "2014-05-01";    #### Get: $date    ### [<Now>] Now...    ### [<time>] Time...    ### [<when>] When...    ### Get time[<time>]     ### Get here[<here>]     ### Get file[<file>]     ### Get line[<line>]     my @values = (1..10);    for (@values) {  #### Progress[===         ] % done     ### Round:$_        do_sth($_);    }    sleep 1;    ### Compare lenth...    my $len = length $date;    ### require: $len > 11    sub do_sth()    {        my $a =  shift;        $a *= 2;    }    ### $date    [root@localhost Smart::Comments]# perl 1.pl    ### Get: '2014-05-01'    ### [Thu May  1 22:38:49 2014] Now...    ### [Thu May  1 22:38:49 2014] Time...    ### [Thu May  1 22:38:49 2014] When...    ### Get time[Thu May  1 22:38:49 2014]     ### Get here["1.pl",line 14]     ### Get file[1.pl]     ### Get line[16]     Progress[                ] 0% done                                       ### Round: 1    Progress[=              ] 11% done                                       ### Round: 2    Progress[===            ] 22% done                                       ### Round: 3    Progress[=====          ] 33% done                                       ### Round: 4    Progress[======         ] 44% done                                       ### Round: 5    Progress[========       ] 55% done                                       ### Round: 6    Progress[==========     ] 66% done                                       ### Round: 7    Progress[===========    ] 77% done                                       ### Round: 8    Progress[=============  ] 88% done                                       ### Round: 9    ### Round: 10    ###  Compare lenth...    ### $len > 11 was not true at 1.pl line 27.    ###     $len was: 10
功能 显示变量的值 跟踪循环 验证断言 用法
#!/usr/bin/env perluse strict;use Smart::Comments;my $test = "Nice to meet you "### $test[root@localhost Smart::Comments]# perl 1.pl ### $date: 'Nice to meet you '

使用3个#号,可以打印出后面的变量值 增加#号可以让模块更智能,最多5个#号

DeBUGging

### Label: Expression

打印变量值和标签

### Expression

打印变量

### text...
进度条

可以用<time> <here> <file> <line>

获得时间文件和行文件名

检查和断言

### require: BOolEAN_EXPR

### assert: BOolEAN_EXPR

### ensure: BOolEAN_EXPR

### insist: BOolEAN_EXPR

### require: $min < $result && $result < $max

如果表达式是假,注释就相当于执行dIE 命令,否者什么都不做:

### $min < $result && $result < $max was not true at demo.pl line 86.###     $min was: 7###     $result was: 1000004###     $max was: 99

### check: BOolEAN_EXPR

### confirm: BOolEAN_EXPR

### verify: BOolEAN_EXPR

就是上面的warn的版本

进度条
foreach my VAR ( List ) {       ### Progressing...   donefor my VAR ( List ) {           ### Progressing...   doneforeach ( List ) {              ### Progressing...   donefor ( List ) {                  ### Progressing...   donewhile (CONDITION) {             ### Progressing...   doneuntil (CONDITION) {             ### Progressing...   donefor (INIT; CONDITION; INCR) {   ### Progressing...   done

用C风格的循环,左边的花括号{放在同一行,把注释也放到这行

for (@candIDates) {       ### Evaluating...     done

执行效果如下,模拟...到达右边的字符

Evaluating                          doneEvaluating......                    doneEvaluating.............             doneEvaluating...................       doneEvaluating..........................done

当然可以把3个. 换成3个:=、 |

也可以加入百分比的进度%

for (@candIDates) {       ### Evaluating [===|    ] % done效果如下Evaluating [|                ]   0% doneEvaluating [===|             ]  25% doneEvaluating [========|        ]  50% doneEvaluating [============|    ]  75% doneEvaluating [=================] 100% donefor (@candIDates) {       ### Evaluating |===[%]    |效果如下Evaluating |[0%]                       |Evaluating |=[25%]                     |Evaluating |========[50%]              |Evaluating |===============[75%]       |Evaluating |===========================|

对于开放式的循环,比如一个带判断的while循环,%就代表循环次数

时间估计

for循环的注释中,如果一次循环超过15秒,就会出现一个剩余时间故事的框 比如

for (@seven_samurai) {      ### fighting: [|||    ]    fight();    sleep 5;}效果:fighting: [                           ]fighting: [||||                       ]fighting: [|||||||||                  ]  (about 20 seconds remaining)fighting: [||||||||||||||             ]  (about 20 seconds remaining)fighting: [||||||||||||||||||         ]  (about 10 seconds fighting: [|||||||||||||||||||||||    ]  (less than 10 seconds remaining)fighting: [|||||||||||||||||||||||||||]
依赖

都是核心模块,所以直接down下来,编译安装就可以了

Filter::Simple version.pm List::Util Data::Dumper Text::Balanced 参考

http://search.cpan.org/~dconway/Smart-Comments-1.000005/lib/Smart/Comments.pm

总结

以上是内存溢出为你收集整理的perl模块之Smart::Comments全部内容,希望文章能够帮你解决perl模块之Smart::Comments所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1277234.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存