Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!nstn.ns.ca!news.cs.indiana.edu!spool.mu.edu!rex!wuarchive!usc!elroy.jpl.nasa.gov!ncar!noao!amethyst!math.arizona.edu!weg From: weg@convx1.ccit.arizona.edu (Eythan Weg) Newsgroups: comp.lang.perl Subject: Re: does perl have an "in" operator? Message-ID: Date: 15 May 91 21:17:08 GMT References: <1991May15.153547.9282@iwarp.intel.com> Sender: news@amethyst.math.arizona.edu Distribution: comp Organization: University of Arizona, Economics Dept. Lines: 25 In-reply-to: merlyn@iwarp.intel.com's message of 15 May 91 15:35:47 GMT In article <1991May15.153547.9282@iwarp.intel.com> merlyn@iwarp.intel.com (Randal L. Schwartz) writes: In article , rusty@groan (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? @array = ( 1, 2, 3 ); print "found one\n" if grep($_ == 1, @array); print "found four\n" if grep($_ == 4, @array); Remember that grep() returns the number of matches in a scalar context. Can this work too? @array = ( 1, 2, 3 ); print "found one\n" if grep(/1/, @array); print "found four\n" if grep(/4/, @array); Eythan