> From: Jeff Pinyan [mailto:jeffp@crusoe.net] > Sent: Wednesday, April 12, 2000 10:34 > To: fwp@technofile.org > Subject: Re: [FWP] sifting > > > On Apr 12, Jeff Pinyan said: > > > sub grep_sift { > > my @sifted = (); > > my @list = @{ shift() }; > > > > for my $re (@_) { > > my @normal; > > push @sifted, grep { > > ($_ =~ $re) ? 1 : do { push(@normal, $_), 0 } > > } @list; > > @list = @normal; > > } > > > > return (@sifted,@list); > > } > > I sped up grep-sift, and now it seems to run consistently > faster. I'll > keep testing though. > > http://www.pobox.com/~japhy/DALnet-perl/sift/ This should be faster for your loop, as it avoids copying the remaining list on each pass: for my $re (@_) { for (my $i = 0; $i < @list; ++$i) { $list[$i] =~ /$re/ and push @sifted, splice @list, $i--, 1; } } -- Larry Rosler Hewlett-Packard Laboratories http://www.hpl.hp.com/personal/Larry_Rosler/ lr@hpl.hp.com ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe