Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cis.ohio-state.edu!sample.eng.ohio-state.edu!purdue!haven.umd.edu!mimsy!mojo!ziegast From: ziegast@eng.umd.edu (Eric W. Ziegast) Newsgroups: comp.lang.perl Subject: Re: A question on associative arrays Message-ID: <1991May30.174847.907@eng.umd.edu> Date: 30 May 91 17:48:47 GMT References: <1991May30.134223.23225@Think.COM> Sender: news@eng.umd.edu (C-News) Distribution: na Organization: uunet Lines: 21 In article <1991May30.134223.23225@Think.COM> sid@think.com (Sid Stuart) writes: > >I am writing a Perl application in which I would like to store >into an associative array only if an entry for that key does >not exist. The problem is I may come up with duplicate keys and >I don't want to overwrite the contents of an entry. Is there a >cheap way to find out if a key is in use? By cheap I mean other >than using the functions "keys" or "each" to search through all >the keys of the array. print defined($assoc{$key}) ? "$assoc{$key}\n" : "Key $key undefined\n"; So long as you don't set $assoc{$key} to a value (even ""), that entry in the associative should be undefined. Eric Z. -- +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ | Eric W. Ziegast Internet: ziegast@eng.umd.edu | | Univ. of Merryland Phonenet: Eric@[301.405.3689] | +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+