Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: grep as apply (was Re: = @array?) Message-ID: <7158@jpl-devvax.JPL.NASA.GOV> Date: 23 Feb 90 22:03:42 GMT References: <15193@bfmny0.UU.NET> <100197@convex.convex.com> <1990Feb23.190455.2653@iwarp.intel.com> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 27 In article <1990Feb23.190455.2653@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: : In article <100197@convex.convex.com>, tchrist@convex (Tom Christiansen) writes: : | @array += 3; : | : | is nice (and I don't even know APL :-) but also unnecessary since you : | can always use: : | : | grep($_ += 3, @array); : : Ahem. : : grep($_ += 3 || 1, @array); : : or you have just lost your zero elements. Remember, grep is both : apply *and* select. Get that idiom *down*! Er, note that he's adding to @array in place. The selection only applies to the returned array value. If he'd said @array = grep($_ += 3, @array); then you'd be righter. : $,=' ';print grep(s/^.//, sort "2another","4hacker,","1Just","3Perl"); Pushed another Hal jerker, Larry