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]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to