全局符号需要明确的程序包名称

全局符号需要明确的程序包名称

本文介绍了Perl:全局符号需要明确的程序包名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我一直在尝试找到解决方案,但是到目前为止,我在网上阅读的所有内容都与范围问题有关,而不是与 my 声明变量.

So I've been attempting to find the solution to this but so far everything I've read online has to do with scope issues and not declaring the variables with the my keyword. However, I can't seem to fix the issues because I've declared everything at the top and, to me at least, it seems I don't have scope issues. My errors for the following code are:

Global symbol "$filename" requires explicit package name at read_ids.pl line 6.
Global symbol "$filename" requires explicit package name at read_ids.pl line 8.
Global symbol "$filename" requires explicit package name at read_ids.pl line 9.
Global symbol "$filename" requires explicit package name at read_ids.pl line 22.

代码:

use strict;
use warnings;

#Create array of IDs.
my @ids
my $filename = 'ids.csv';

open(my $fh, '<:encoding(UTF-8)', $filename)
    or die "Could not open file '$filename'.";

#Read line using the readline operators <>.
while (my $row = <$fh>) {
#Remove any newline characters from line using the chomp() command.
    chomp $row;
    push @ids,'$row';
#  print "$row\n";
}

foreach (@ids) {
    print "$_\n";
}
print "Read '$filename' successfully.\n";

推荐答案

您的代码需要以下语句

my $filename;

它当前不包含该语句.相反,它包含以下无效语句:

It does not currently contain that statement. It contains the following invalid statement instead:

my @ids my $filename = 'ids.csv';

Perl甚至告诉过你.

Perl even told you about it.

syntax error at a.pl line 6, near "@ids
my "

首先解决第一个错误.为此,请添加缺少的分号.

Fix the first error first. Do so by adding the missing semi-colon.

这篇关于Perl:全局符号需要明确的程序包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 14:36