Sure, you just about have it, but don't use $hash{$_} == "" as someone else said, just use $hash{$_} eq ""
Also, if you name your iterator $hash_key, then don't use $_, use $hash_key...so the final code would be foreach my $hash_key (keys %hash) { if( $hash{$hash_key} eq "" ) { print "\$hash{$hash_key} contains a null value!"; } } ----- Original Message ----- From: "Daniel Falkenberg" <[EMAIL PROTECTED]> To: "Tanton Gibbs" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Wednesday, April 10, 2002 2:36 AM Subject: Re: Checking if a hash has blank values. > Hi Tanton, > > Yes, but what I really want it to do is go though all the values of the > hash and if any of them contain null values then print that out and tell > me whick key(s) value(s) contains null values? Is this possible? > > Therefore... > > foreach $hash_key (keys %hash) { > if ($hash{$_} == "" || $hash{$_} eq "") { > print $hash{$hash_key}, "Contains a null value!\n"; > else { > print "It worked!\n"; > } > } > > Thx, > > Dan > > > On Wed, 2002-04-10 at 15:52, Tanton Gibbs wrote: > > If you want to test all of them, you can say > > > > $hash{$_} eq "" and die "Empty hash!" foreach( keys %hash ); > > ----- Original Message ----- > > From: "Eric Beaudoin" <[EMAIL PROTECTED]> > > To: "Daniel Falkenberg" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > > Sent: Wednesday, April 10, 2002 2:22 AM > > Subject: Re: Checking if a hash has blank values. > > > > > > > At 02:08 2002.04.10, you wrote: > > > >Hey all, > > > > > > > >I have created a hash that looks similar to the following... > > > > > > > >%hash ( > > > > 'test1' => $test1, > > > > 'test2' => $test2, > > > > 'test3' => $test3, > > > >); > > > > > > > >Now is it possible to have a little piece of code check the values of > > > >that hash and see if their are any blank fields? > > > > > > > >Something like... > > > > > > > >if ($hash($_) eq "" || $hash($_) == ""} > > > > print "These hash keys $hash($_) did not contain any data!\n"; > > > >} else { > > > > print "It worked!"; > > > >} > > > > > > > >Regards, > > > > > > > >Dan > > > > > > Hashes use the {}, not the (). > > > > > > $hash{$_} == "" is not right. == is for numerical comparaison so perl > > automagicaly transform each side to a number before resolving the ==. > > > > > > This means that "a" == "b" returns true and "This is a value" == "" also > > returns true. Not what you want I beleive. > > > > > > Your first test ($hash{$_} eq "") should work like you intend it. > > > > > > You can be lazy and test like this > > > > > > if($hash{$_}) then { print "There is a value\n" } > > > > > > if you know in advance that none of your value can be the number or the > > string "0". > > > > > > Hope this helps. > > > > > > > > > ---------------------------------------------------------- > > > Éric Beaudoin <mailto:[EMAIL PROTECTED]> > > > > > > > > > -- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > -- > ============================== > VINTEK CONSULTING PTY LTD > (ACN 088 825 209) > Email: [EMAIL PROTECTED] > Web: http://www.vintek.net > Tel: (08) 8523 5035 > Fax: (08) 8523 2104 > Snail: P.O. Box 312 > Gawler SA 5118 > ============================== > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]