home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!cs.utexas.edu!usc!elroy.jpl.nasa.gov!nntp-server.caltech.edu!harry!bruce
- From: bruce@harry.ugcs.caltech.edu (Bruce J Bell)
- Subject: how do you tell if a key exists?
- Message-ID: <bruce.714890738@harry>
- Sender: news@cco.caltech.edu
- Nntp-Posting-Host: harry.ugcs.caltech.edu
- Organization: California Institute of Technology, Pasadena
- Date: Thu, 27 Aug 1992 04:45:38 GMT
- Lines: 24
-
- My question is: is there a straightforward way to tell if a
- key exists in an associative array?
-
- The problem is, an entry can exist whose value is undefined:
- $a{"key"}=69; undef $a{"key"}
- or
- undef $x; $a{"key"}=$x
-
- You can search for it:
- $a{"key"}
- or delete it:
- delete $a{"key"}
- but I don't know how you can tell the difference between an
- undefined value copied from the array entry (key does exist)
- and an undefined value you get because there's no such entry
- (key doesn't exist).
-
- Of course you could always check all the keys in the array,
- one by one, but is there a way to avoid that?
-
- Replies to me, please.
-
-
- -- Bruce
-