Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!relay.nswc.navy.mil!oasys!mimsy!midway!msuinfo!netnews.upenn.edu!jes From: jes@mbio.med.upenn.edu (Joe Smith) Newsgroups: comp.lang.perl Subject: Re: global pattern matching question Message-ID: Date: 5 May 91 23:05:50 GMT References: <1991May4.010307.11792@jpl-devvax.jpl.nasa.gov> Sender: news@netnews.upenn.edu Distribution: comp Organization: University of Pennsylvania, Philadelphia, PA Lines: 49 Nntp-Posting-Host: mbio.med.upenn.edu In-reply-to: lwall@jpl-devvax.jpl.nasa.gov's message of 4 May 91 01:03:07 GMT In article <1991May4.010307.11792@jpl-devvax.jpl.nasa.gov> lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) writes: > In 4.003, $` is unfortunately broken within s/// because of a fix to > something else. That'll be fixed in patch 4. As a workaround you > could use length($seq) - length($') - length($1). Yeah, blech... Oops, I just saw the other bug report. The book says that $` and $' aren't generated unless they're mentioned. In an expression like length $`, does perl actually generate a copy of this piece of the original string just to determine the match position, or is the length just calculated from the match position? > An option to s/// not to do replacement would be interesting, though And to think I've always wondered how such wonderfully convoluted language design happens... > there might be a better way--maybe an initial offset for m//, or > allowing patterns in index(). This seems more direct, but the ability to bind an action to the match is also very important. Perhaps access to a primitive pattern matching function (the way splice is related to push, pop, etc.) would be reasonable: $options = "oi"; for ($pos = 0; $matched = regexp( $pattern, $seq, $pos, $options ); $pos += $matched ) { push( @positions, $pos ); push( @sites, subst($seq, $pos, $matched )); } I think you could replicate the match and substitute capabilities with that (subst($seq, $pos, $matched ) = "your replacement here..."), with arbitrary actions on a match and without a lot of extra string copies. It'll never fit on one line, but I could live with that.