Text::Autoformat Perl 错误

Text::Autoformat error in Perl

我得到了以下打印目录中文件内容的 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 模块中的错误吗?

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

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