perl – 文件打开错误 – 全局符号“$infilename”需要显式包名

前端之家收集整理的这篇文章主要介绍了perl – 文件打开错误 – 全局符号“$infilename”需要显式包名前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在编写我的第一个perl脚本,无法编译它.我想读取一个文件,并将符合正则表达式条件的每一行输出到一个新文件.我得到一个“全局符号需要显式包名称错误,这似乎与我读过的可变范围问题有关.我无法弄清楚我的代码有什么问题.

码:

#!/usr/bin/perl -w
use strict;
use warnings;

print "Stripping lines from data dump where WREN column is FFF\n" 

my $infilename = "./test_in.txt";
my $outfilename = "./test_out.txt";
my $in = undef;

open($in,"<",$infilename)  or die "Can't open $infilename: $!";
open(my $out,">",$outfilename) or die "Can't open $outfilename: $!";

while (<$in>) {     # assigns each line in turn to $_
   if (/.{73}FFF/){
      print $out $_;
   }
}

错误信息:

Syntax error at strip_nonwrites.pl line 8,near "my "
Global symbol "$infilename" requires explicit package name at strip_nonwrites.pl line 8.
Global symbol "$infilename" requires explicit package name at strip_nonwrites.pl line 12.
Global symbol "$infilename" requires explicit package name at strip_nonwrites.pl line 12.
Execution of strip_nonwrites.pl aborted due to compilation errors.

解决方法

单个语法错误会导致解析器足以在事后产生多个错误错误并不罕见.就是这种情况.

您的第一个错误是需要注意的错误.你在第6行的末尾错过了一个分号(第8行的“我的”附近).

接下来的所有“全局符号……”错误只是通过尝试将行6..8解析为单个命令而产生的混淆.

猜你在找的Perl相关文章