将不可见的符号变得可见

上一篇 / 下一篇  2008-11-20 11:01:30 / 个人分类:Perl

debug时,如果只是试验,最简单的调试方法就是到处添加一些print()语句。
但是这种方式的弊病是,不容易发现一些特殊的字符输出,比如\n\r\t

范例:
一个常见的错误是当从外部资源读入数据时,忘记使用chomp()。
while (<$file_list>){
  warn "Processing $_";
  next unless -e $_;
  &process_file($_);
}
输出中看不出什么问题,但是&process_file sub 却不会执行。
改变调试行,让文件名更加明显:
while (<$file_list>){
  warn "Processing'$_'";
  next unless -e $_;
  &process_file($_);
}
我们将发现所有的文件名末尾都有换行符,fix it:
while (<$file_list>){
 chomp;
  next unless -e $_;
  &process_file($_);
}


TAG: debug Perl

 

评分:0

我来说两句

日历

« 2024-04-30  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 47831
  • 日志数: 80
  • 建立时间: 2008-10-27
  • 更新时间: 2009-07-17

RSS订阅

Open Toolbar