开发者

In Perl, what is the difference between if (%hash) and if (defined %hash)?

What is difference between if (%hash) and if (defined %hash)?

my %hash ;

if ( %hash) {开发者_JAVA技巧 

  print "defined "; 
}

if (defined %hash)  { 
  print "defined ";
}


From perldoc -f defined:

Use of "defined" on aggregates (hashes and arrays) is deprecated. It used to report whether memory for that aggregate has ever been allocated. This behavior may disappear in future versions of Perl. You should instead use a simple test for size:

  if (@an_array) { print "has array elements\n" }
  if (%a_hash)   { print "has hash members\n"   }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜