Global symbol "****" requires explicit package name

claire_wu 2010-06-03 11:15:55
下面是我写的perl script:
use strict;

my $irm_prop = ();
$irm_prop{"wo"} = "value";

run后出错:
Global symbol "%irm_prop" requires explicit package name at temp_2.pl line 6.
Execution of temp_2.pl aborted due to compilation errors (#1)
(F) You've said "use strict" or "use strict vars", which indicates
that all variables must either be lexically scoped (using "my" or "state"),
declared beforehand using "our", or explicitly qualified to say
which package the global variable is in (using "::").

这事我用了'use strict'后报的错,但是irm_prop是全局变量,为什么还会报错呢?
...全文
1356 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jianddddd 2011-12-28
  • 打赏
  • 举报
回复
去掉use strict或者申明变量为my
业祥运维室 2011-01-27
  • 打赏
  • 举报
回复
#!/usr/bin/perl
use strict;
my $data=int(1+rand 100);
while(<>){
our $count++;
if ($_ == $data) {last;}
elsif($_ > $data) {print "too big";}
else {print "small";}
}
print "the count is $count"



也报同样的错误
plaeks 2010-06-03
  • 打赏
  • 举报
回复
你声明的是$irm_prop,而你使用的是%irm_prop,两者不是同一个变量。
claire_wu 2010-06-03
  • 打赏
  • 举报
回复
多谢提醒!哈希表用“%”引导。

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧