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

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

my %hash ;

if ( %hash) { 

  print "defined "; 
}

if (defined %hash)  { 
  print "defined ";
}
+3
source share
1 answer

From perldoc -f it is defined :

The use of " defined" for aggregates (hashes and arrays) is deprecated. He reported a memory for this collection has ever been allocated. This may disappear in future versions of Perl. Instead, you should use a simple test for size:

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

Source: https://habr.com/ru/post/1753294/


All Articles