home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!oracle!unrepliable!bounce
- Newsgroups: comp.lang.perl
- From: tshields@oracle.com (Thomas A. Shields Jr.)
- Subject: Repeat string matching/substituting ?
- Message-ID: <TSHIELDS.92Jul23160911@woodie.oracle.com>
- Sender: usenet@oracle.us.oracle.com (Oracle News Poster)
- Nntp-Posting-Host: woodie.us.oracle.com
- Organization: Oracle Corporation
- Distribution: comp
- Date: Fri, 24 Jul 1992 00:09:11 GMT
- X-Disclaimer: This message was written by an unauthenticated user
- at Oracle Corporation. The opinions expressed are those
- of the user and not necessarily those of Oracle.
- Lines: 24
-
- I am relatively new to Perl, and I am trying to do what seems to be a
- fairly simple operation, without much success.
-
- I need to surround each occurrence of a string within a line with
- 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!
-
- -ts-
- --
- Tom Shields, Multimedia Developer (415) 506-6182 tshields@oracle.com
- Oracle Corporation, Box 659412, Redwood Shores, CA, 94065 =What .sig virus?=
-