Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all Keys in a hash have a value in Perl

Tags:

perl

How do you determine if all hash keys have some value ?

like image 810
joe Avatar asked Dec 19 '25 02:12

joe


1 Answers

From perldoc -f exists:

               print "Exists\n"    if exists $hash{$key};
               print "Defined\n"   if defined $hash{$key};
               print "True\n"      if $hash{$key};

               print "Exists\n"    if exists $array[$index];
               print "Defined\n"   if defined $array[$index];
               print "True\n"      if $array[$index];

A hash or array element can be true only if it's defined, and defined if it exists, but the reverse doesn't necessarily hold true.

like image 191
Alan Haggai Alavi Avatar answered Dec 20 '25 17:12

Alan Haggai Alavi