当前位置: > 有一个perl程序,中state的用法错误...
题目
有一个perl程序,中state的用法错误
程序如下:
/usr/bin/perl
use strict;
sub greet{
state @people;
my $num;
foreach (@_){
push (@people,$_);
}
$num = @people;
if($num == 1){
print " 你是第一个来的人! ";
}else{
print " $people[$#people-1]已经比你先到了 ";
}
}
###开始进行一些测试#########################
&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.p

提问时间:2021-03-31

答案
state这个是在perl 5.0.10里面提供的功能,需要明确指明,才可以使用,如何指明:加入这行:use feature qw(state);或者加入这行:use 5.010;#!/usr/bin/perluse strict;use 5.010;sub greet{ state @people; ...
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
1,人们染上烟瘾,最终因吸烟使自己丧命.
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.