我正在用Perl编写我的第一个程序,并写道:
use strict;
use warnings;
$animal = "camel";
print($animal);
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我从Windows命令行获取这些消息:
Global symbol "animal" requires explicit package name at stringanimal.pl line 3
Global symbol "animal" requires explicit package name at stringanimal.pl line 4
Run Code Online (Sandbox Code Playgroud)
请问,这些消息是什么意思?
我正在编写我的第一个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 $_;
}
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
syntax error at strip_nonwrites.pl line 8, near "my "
Global symbol …Run Code Online (Sandbox Code Playgroud) my %order;
while ( my $rec = $data->fetchrow_hashref ) {
push @{ $result{ $rec->{"ID"} } }, $rec->{"item"};
push @order, $rec->{ID};
}
Run Code Online (Sandbox Code Playgroud)
我得到全局符号"@order"需要显式包名称push @order, $rec->{ID};
perl ×3