Perl中的Text :: Autoformat错误

时间:2015-09-23 11:05:00

标签: perl autoformatting

我得到了以下Perl脚本,用于在目录中打印文件内容:

#!/usr/bin/perl -w

use strict;
use warnings;
use Text::Autoformat;

my $NER = "$ARGV[0]/Data/NER_$ARGV[1]";

foreach my $fp (glob("$NER/*")){
    if (-s $fp){
        # Open file to read
        open my $fz, "<", $fp or die;
        binmode $fz, ":encoding(UTF-8)";
        while(my $row = <$fz>){
            chomp($row);
            print "$row\n";
        }
        close $fz or die;
    }
}

脚本运行正常,但每次打开新文件时都会出现此警告:

Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.

...

这是正在打印的文件的示例:

22-22   today   DATE
25-25   NY  LOCATION

这是Text::Autoformat模块中的错误吗?

1 个答案:

答案 0 :(得分:2)

你观察到的是正常的,你也要求它:the -w option switch enables global warnings

你应该在Perl 5.6及更高版本中使用词法警告(pragma use warnings),所以删除选项开关。