Chinaunix首页 | 论坛 | 博客
  • 博客访问: 837627
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-08-23 10:15:02

在hash中,当检验一个元素值是否被定义是用defined,当检验一个key在hash中是否存在时,用exists。exists 和 defined 的差异及用法示例:
  1. $hash{"test"}='what';

  2. if (exists $hash{"test100"}){
  3.     print "test100";
  4. }

  5. if (defined $hash{"test"}){
  6.     print "yes test";
  7. }
  8.        
  9. yes test
defined

Returns a Boolean value telling whether EXPR has a value other than the undefined value . If EXPR is not present, $_ will be checked.

exists

Given an expression_r_r that specifies a hash element or array element, returns true if the specified element in the hash or array has ever been initialized, even if the corresponding value is undefined.

阅读(380) | 评论(0) | 转发(0) |
0

上一篇:[Perl] Perl 特殊变量

下一篇:perl links

给主人留下些什么吧!~~