Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!agate!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: does perl have an "in" operator? Message-ID: <1991May15.153547.9282@iwarp.intel.com> Date: 15 May 91 15:35:47 GMT References: Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Distribution: comp Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 60 In-Reply-To: rusty@groan.Berkeley.EDU (Rusty Wright) 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. (Note for the JAPH: For those of you that have been waiting for a better JAPH comparable to my earlier works, check this one out... look carefully... I truly am selecting one of the funny lines at random.) srand;eval join("",reverse sort split(/:/,(split(/\n/,<<'-- '))[rand(32)])) nother Perl hac:,":print "Just a:ker hacker,":nother Perl:print "Just a nother Perl hack:er,":print "Just a print "Just anot:her Perl ha:":cker, other Perl hac:ker,":print "Just an another Perl: hacker,":print "Just Perl hacker,": another:print "Just print "Just an:other :Perl hacker," l hac:ker:other Per:print "Just an:," print "Just an:l hac:ker,":other Per other Perl ha:cker,":print "Just an print "Just a:nother Perl :hacker," acker,":other Perl h:print "Just an nother P:print "Just a:erl hacker," print "Just a:l hacker,":nother Per acker:,":nt "Just anot:pri:her Perl h pr:Perl hacker,":her :int "Just anot print "Just a:cker,":nother Perl ha l hacker,:other Per:print "Just an:" her P:not:print "Just a:erl hacker," ":print "Just anot:her Perl hacker, er,":her Perl hack:print "Just anot cker,:other Perl ha:print "Just an:" "Just another:print : Perl hacker," her Perl ha:print "Just an:cker,":ot not:her Perl hacker,:print "Just a:" print "Just a:acker,":nother Perl h print "Just anot:,":her Perl hacker nother :print "Just a:Perl hacker," oth:cker,":er Perl ha:print "Just an Perl hacker,":nother:print "Just a her Perl hacker:nt "Just anot:pri:," -- -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/