Perl模块推荐-Smart::Comments

一月 8th, 2010 Posted in Perl | 阅读次数: 634 次

原文:http://www.hiadmin.com/?p=1357

调试有两种方法
一种是使用调试器.从内存里面抓出你感兴趣的变量
观察变量和过程调用
这个方法不会干扰到代码
但是一般大家都不太喜欢用这个
因为各种调试器需要学习
而且太底层了
更多的情况下面,我们只要把变量的内容输出就可以了
这个时候我们一般选择在代码的各个地方插入print或者printf
缺点就是会弄乱代码
而且调试好要删掉,下次需要的时候又要加上.
改进一点的方法就是加上条件判断
如果设定的debug变量为真时就输出
缺点就是每个print的地方都会变成判断,一句变三句.

那么,有没有更方便的方法呢
如果你用Perl
那么恭喜你,你拥有庞大的CPAN,并且里面有我今天要推荐的主角
Smart::Comments
简单来说,就是会把特定的注释变成调试语句
例如简单的程序

  1. #!perl -w
  2. use Smart::Comments;
  3. $a{‘a’}[0]=20;
  4. #debug info
  5. ### %a
  6. $a{‘a’}[0]++;
  7. ### %a
  8. print $a{‘a’}[0];

现在我们可以发现在###注释的地方
程序把%a哈希输出了
这样只要通过简单的是否use Smart::Comments就可以在调试模式下切换了
还有从命令行调用的方式.这样连第一句use也不用了
perl -MSmart::Comments test.pl
搞定~
你只要通过加上参数就能获取调试信息
是不是特别方便?

相关日志:

Tags:

2 Responses to “Perl模块推荐-Smart::Comments”

  1. digital music distribution Says:

    You should check this out…

    [...] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well [...]……


  2. Nice Post Says:

    Nice Post…

    [...]高进波博客 – 零起点一步配置你的linux服务器,linux博客,linux教程,web架构 » Blog Archive » Perl模块推荐-Smart::Comments[...]…


留下您的脚印