home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!darwin.sura.net!wupost!news.utdallas.edu!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: Repeat string matching/substituting ?
- Message-ID: <1992Jul24.131118.7748@news.eng.convex.com>
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Nntp-Posting-Host: pixel.convex.com
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- Organization: CONVEX Realtime Development, Colorado Springs, CO
- References: <TSHIELDS.92Jul23160911@woodie.oracle.com>
- Distribution: comp
- Date: Fri, 24 Jul 1992 13:11:18 GMT
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 33
-
- From the keyboard of tshields@oracle.com (Thomas A. Shields Jr.):
- :I need to surround each occurrence of a string within a line with
-
- Blessed (and few :-) are they who spell occurrence right. :-)
-
- :begin and end tags, i.e. "the place the fox went is the chickencoop"
- :with keyword "the" needs to become "<begin>the<end> place
- :<begin>the<end> fox went is <begin>the<end> chickencoop".
- :
- :Here's what I tried:
- :
- :#!/usr/bin/perl -p
- :while (/the/g) {
- : $_ = $` . "<begin>" . $& . "<end>" . $';
- :}
- :
- :but this fails unpredictably, probably because //g doesn't like the
- :fact that $_ is changing on it. Any insight into how //g works
- :internally, or a better way to accomplish this in general would be
- :much appreciated. Thanks!
-
- I think it would be better to put the /g on an s/// expr in this case:
-
- perl -pe 's/\bthe\b/<begin>the<end>/g'
-
- --tom
-
-
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
- If you consistently take an antagonistic approach, however, people are
- going to start thinking you're from New York. :-)
- --Larry Wall to Dan Bernstein in <10187@jpl-devvax.JPL.NASA.GOV>
-