Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!voder!nsc!taux01!tasu8c!arielf From: arielf@tasu8c.UUCP (Ariel Faigon) Newsgroups: comp.lang.perl Subject: Re: does perl have an "in" operator? Summary: Use an associative array Keywords: associative-array key Message-ID: <5852@taux01.nsc.com> Date: 15 May 91 12:47:27 GMT References: Sender: netnews@taux01.nsc.com Reply-To: arielf@tasu8c.UUCP (Ariel Faigon) Distribution: comp Organization: National Semiconductor (IC) Ltd, Israel Lines: 29 +--- In the ref. article rusty@groan.Berkeley.EDU (Rusty Wright) wrote: | I've used a language where with arrays there's an "in" operator that | checks to see if an element is in an arry. For example, if you do | | @array = ( 1, 2, 3 ); | | if ( 1 in @array ) { print "true\n"; } | | it would print true. Does perl have anything like this? +--- Sure it has. Only the syntax is a bit different... What you want is an associative array: %array = (1,1, 2,1, 3,1); # pairs of key,value... print "true\n" if ($array{1}); If you don't want to initialize the whole array at once, you can also use: $array{1} = 1; $array{2} = 1; $array{3} = 1; print "true\n" if ($array{1}); -- --- Ariel Faigon National Semiconductor Corp. (NSTA Design Center) 6 Maskit St. P.O.B. 3007, Herzlia 46104, Israel Tel. +972 52-522272