Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Best way to nullify an intersection Message-ID: <8593@jpl-devvax.JPL.NASA.GOV> Date: 4 Jul 90 00:16:25 GMT References: <601@inpnms.ROCKVILLE.DG.COM> <15631@bfmny0.BFM.COM> <604@inpnms.ROCKVILLE.DG.COM> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 27 In article <604@inpnms.ROCKVILLE.DG.COM> logan@rockville.dg.com (James L. Logan) writes: : In article <15631@bfmny0.BFM.COM> tneff@bfmny0.BFM.COM (Tom Neff) writes: : # : # @B=grep(!do {$x=$_; grep($x eq $_,@A);},@B); : # : : Could someone explain this construct? I've only been using perl : for a week now... That's just a funny way of writing two nested loops. It's more or less equivalent to @outer_result = (); foreach $_ (@A) { $x = $_; @inner_result = (); foreach $_ (@B) { push(@inner_result,$_) if $x eq $_; } push(@outer_result, $_) if @inner_result; } @B = @outer_result; As such, it's just another O(n**2) algorithm. Better to use the associative array method mentioned earlier, which is basically a linear algorithm. Larry