Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!hsdndev!husc6!genrad!genrad.com!jpn From: jpn@genrad.com (John P. Nelson) Newsgroups: comp.lang.perl Subject: Re: does perl have an "in" operator? Message-ID: <41515@genrad.UUCP> Date: 15 May 91 18:34:59 GMT References: Sender: news@genrad.UUCP Distribution: comp Organization: GenRad, Inc., Concord, Mass. Lines: 24 In article rusty@groan.Berkeley.EDU (Rusty Wright) writes: >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? Well, sort of. "grep" can be used to implement this fairly easily using an expression that contains ==: if (grep(1 == $_, @array)) { print "true\n"; } This works essentially the same as your "in" operator. Unfortunately, "grep" doesn't stop the first time it finds a match, it iterates over the whole array no matter what. john nelson uucp: {decvax,mit-eddie}!genrad!jpn domain: jpn@genrad.com