in reply to Re: Re: Peeling the Peelings
in thread Peeling the Peelings
As my original attempt was so crap, I thought I'd take another crack. Abandoning any attempt at validation and avoiding the regex engine completely, I came up with this which seems to be about 15% better than the best so far.
sub peel { my( $s, $n ) = @_; my( $start, $stop ) = ( 0, length $s ); ($start,$stop) = ( 1 + index( $s, '(', $start ), rindex( $s, ')', $stop -1 ) # reformatting_for_posting error corrected # Was ) while $n-- > 0 and index( $s, '(', $start +1 ) > 0; ) while $n-- and index( $s, '(', $start +1 ) > 0; substr $s, $start, $stop - $start; } Rate mine-less-lgnt buk2 mine-less-lgnt 918/s -- -15% buk2 1075/s 17% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Peeling the Peelings
by bobn (Chaplain) on Jul 03, 2003 at 13:18 UTC | |
by BrowserUk (Patriarch) on Jul 03, 2003 at 13:28 UTC | |
by bobn (Chaplain) on Jul 03, 2003 at 23:17 UTC |