Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

control if value exist in a Hashtable

Status
Not open for further replies.

r2d22y

Technical User
Nov 30, 2004
46
SE
Hello

Lets say I have a hashtable myhash{'valueA'}

If I have to controll if their is a value in myhash{'valueA'}
I thought I could do:

if(myhash{'valueA'} eq ""){
statement 1
}else{
statement 2
}

but when I do the control above it always goes to statement2 even if values doesnt exist in myhash{$valueA} (?)

Obviously this is wrong to do but how should I control if a value exist in an hashtable (it is a string).

What I want to do is to build up a string of format "234,234,456,"going through values in my hashtable so..

while (@row = $sth2->fetchrow_array ()) {
if($agentsinqueue{$que} eq ""){
$agentsinqueue{$que}=$row[0];

}else{
$agentsinqueue{$que}=$agentsinqueue{$que}.",".$row[0];
}


Regards/D_S
 
Code:
my %h = (
  A => 'something',
  B => 'other'
);

print "yes\n" if exists $h{A};
print "no\n" if exists $h{C};

# don't be tempted by
print "don't do this" if defined $h{C}; # autovivifies $h{C}
# because
print "no\n" if exists $h{C}; # oops: it now exists, although it's undefined


["]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.["]
--Maur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top