> Message du 06/10/08 15:25
> De : "loody"
> A : "Perl beginners"
> Copie à :
> Objet : How to check empty hash value properly?
>
>
> Dear all:
> I want to use hash to keep my records.
> But before using it, I want to determine whether the value of the key exist?
> Below is my source code:
> if($hash{$key} eq "")
> {
> print "the value of the $key is empty\n";
> $hash{$key}=1;
> }
> else
> {
> $hash{$key}++;
> }


Shouldn't do that.
For checking if a hash key was there, use "exists":

if (exists $hash{$key} ) { do something }


In your case, for increasing a hash value, you don't need to initialize it.Just 
say:

$hash{$key} ++;

If this pair of key/value doesn't exist, Perl will creat it for you silently.


Regards,
Jeff.

 Créez votre adresse électronique [EMAIL PROTECTED] 
 1 Go d'espace de stockage, anti-spam et anti-virus intégrés.

Reply via email to