home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5533 < prev    next >
Encoding:
Text File  |  1992-08-26  |  1.0 KB  |  36 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!cs.utexas.edu!usc!elroy.jpl.nasa.gov!nntp-server.caltech.edu!harry!bruce
  3. From: bruce@harry.ugcs.caltech.edu (Bruce J Bell)
  4. Subject: how do you tell if a key exists?
  5. Message-ID: <bruce.714890738@harry>
  6. Sender: news@cco.caltech.edu
  7. Nntp-Posting-Host: harry.ugcs.caltech.edu
  8. Organization: California Institute of Technology, Pasadena
  9. Date: Thu, 27 Aug 1992 04:45:38 GMT
  10. Lines: 24
  11.  
  12. My question is:  is there a straightforward way to tell if a
  13. key exists in an associative array?
  14.  
  15. The problem is, an entry can exist whose value is undefined:
  16.   $a{"key"}=69; undef $a{"key"}
  17. or
  18.   undef $x; $a{"key"}=$x
  19.  
  20. You can search for it:
  21.   $a{"key"}
  22. or delete it:
  23.   delete $a{"key"}
  24. but I don't know how you can tell the difference between an
  25. undefined value copied from the array entry (key does exist)
  26. and an undefined value you get because there's no such entry
  27. (key doesn't exist).
  28.  
  29. Of course you could always check all the keys in the array,
  30. one by one, but is there a way to avoid that?
  31.  
  32. Replies to me, please.
  33.  
  34.  
  35. -- Bruce
  36.