Microsoft
Software
Hardware
Network
Question : easy question (if else / foreach)
trying to test if key exists in hash
if exists in hash, want to print value and offer to change value (I can change value ok so didn't include code)
if dosen't exist, want to offer to add (know how, but if else / foreach doesn't work).
now. this should print two trues for you unless you enter a number. you are supposed to enter apple or sky to get a true, but any sting gets a true. The if then always tests true. What is going on here?
#!/usr/bin/perl
%tab=("apple","red","sky",
"blue");
$val=
;
foreach $key(keys(%tab)){
if($val==$key){
print "\ntrue" . "value is " . $tab{$val};
#want to change part would be here}
else{
print "false - no such key";
#want to add section would be here
}}
********************
I want to use the foreach method to look at each key to do this.
I also want to use the if inside the for each.
THanks
...I've added points because I know this is an unusual way to test for the existance of a key.
Answer : easy question (if else / foreach)
= is assignment, == is numeric equality, eq is string equality
Random Solutions
Outlook 2003 hangs ... white window ... not responding when opening Word/Excel attachments
Can't open certain .JPG images, but other open just fine.
Services Crashing Multiple Times Per Day: wuauserv, bits, browser, trkwks, dmserver, seclogon, lanmanserver, audiosrv, sharedaccess, wzcsvc, and lanmanworkstation
Latex to Text for Windows
SMS_Inventory_Data_Loader
Estimating live chat traffic?
HELP!! Computer gone nuts!!
E-Mail Stuck in Outbox
How to span a large gzip file over many DVDs
Getting a hosts name or IP in an Apache environment variable