关于defined的使用
时间:2011-12-03
来源:互联网
大家好,我写了一段程序,但是发现出现语法错误,请大家指点一下。谢谢!具体源码如下:
Perl code
系统提示:
Use of uninitialized value $_ in print at ./Ex4_4 line 13 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.
请问这个原因是什么?
Perl code
#!/usr/bin/perl use 5.010; use strict; use diagnostics; use feature 'state'; sub greet { state $name; if(!defined($name)) #这里判断静态变量$name是否已经定义 { $name=$_; print "Hi ", $_, "! ", $name, " is also here ! \n"; } else { print "Hi ", $_, "! ", $name, " is also here ! \n"; } } greet("Fred"); greet("Barney");
系统提示:
Use of uninitialized value $_ in print at ./Ex4_4 line 13 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.
请问这个原因是什么?
作者: chennut0802 发布时间: 2011-12-03
你把 @_ 和 $_ 弄混了
Perl code
Perl code
state $name; $_=shift; #加上这行就可以了 if(!defined($name))
作者: ccdbg 发布时间: 2011-12-03
1楼的朋友,加了还是不行啊,还是有问题。
作者: chennut0802 发布时间: 2011-12-03
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28