develooper Front page | perl.beginners | Postings from October 2008

How to check empty hash value properly?

Thread Previous | Thread Next
From:
loody
Date:
October 6, 2008 06:25
Subject:
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}++;
}
It works but I will receive some warning message like:
"Use of uninitialized value in string eq at
F:\driver_source\autoBuild\checkout\test6.pl line 46.
the value of the 9 is empty"
Is there any way to avoid it?
appreciate your help,
miloody

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About