有一个perl程序,中state的用法错误
有一个perl程序,中state的用法错误
程序如下:
/usr/bin/perl
use strict;
sub greet{
state @people;
my $num;
foreach (@_){
push (@people,$_);
}
$num = @people;
if($num == 1){
print "\n你是第一个来的人!\n";
}else{
print "\n$people[$#people-1]已经比你先到了 \n";
}
}
###开始进行一些测试#########################
&greet("tom");
#greet("Lily");
#greet("wangzi");
报错:
Array found where operator expected at ./Geet1.pl line 5,at end of line
(Missing operator before )
syntax error at ./Geet1.pl line 5,near "state @people"
Global symbol "@people" requires explicit package name at ./Geet1.pl line 5.
Global symbol "@people" requires explicit package name at ./Geet1.pl line 8.
Global symbol "@people" requires explicit package name at ./Geet1.pl line 10.
Global symbol "@people" requires explicit package name at ./Geet1.pl line 14.
Global symbol "@people" requires explicit package name at ./Geet1.pl line 14.
Execution of ./Geet1.pl aborted due to compilation errors.
state这个是在perl 5.0.10里面提供的功能,需要明确指明,才可以使用,如何指明:加入这行:use feature qw(state);或者加入这行:use 5.010;#!/usr/bin/perluse strict;use 5.010;sub greet{state @people; ...