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) { 

  print "defined "; 
}

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

Answers


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"   }

Need Your Help

Android - WebView language changes abruptly on Android N

android android-webview locale android-7.0-nougat nexus-6p

I have a multilingual app with primary language English and secondary language Arabic.

How to run a program in Atom Editor?

text-editor atom-editor

I found Atom editor as good free alternative to Sublime text editor. Not able to find a straightforward way to run a program in Atom editor. In my case, I am trying to run a java program. Please le...