🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.perl.misc
5 messages
5 total messages Started by Jeff Dilcher Sun, 28 Jan 1996 00:00
Find and Replace Perl function?
#53
Author: Jeff Dilcher
Date: Sun, 28 Jan 1996 00:00
17 lines
1070 bytes
I have a whole set of web files; about 40 of them.
I would like to change a block of text in each one
(the text is a trailer section that is consistant in each one).

I am a little stumped about how to write a little perl 
routine to do this.  Does Perl have a built in function
that can identify and replace a whole block of lines of text?

Anyone have a little pointer about the best way to go about doing
something like this?

If I have to edit each file manually, and make the changes,
I  might go insane!

Thanks very much!
I can be reached directly at dilcher@cueva.com.
-Jeff
Re: Find and Replace Perl function?
#54
Author: Steven Ericsson Zenith
Date: Sun, 28 Jan 1996 00:00
6 lines
805 bytes
Wouldn't it be easier to do this with sed?

-- 
Steven Ericsson Zenith - Sunnyvale, California.
mailto:Steven@TheTemple.com, http://www.TheTemple.com/Steven/
"Never confuse wisdom with luck." Rule #44
Re: Find and Replace Perl function?
#55
Author: Mike Linksvayer
Date: Sun, 28 Jan 1996 00:00
34 lines
1506 bytes
In article <4egegu$ktj@shellx.best.com>, Jeff Dilcher <dilcher@shellx.best.com> wrote:
>I have a whole set of web files; about 40 of them.
>I would like to change a block of text in each one
>(the text is a trailer section that is consistant in each one).
>
>I am a little stumped about how to write a little perl 
>routine to do this.  Does Perl have a built in function
>that can identify and replace a whole block of lines of text?
>
>Anyone have a little pointer about the best way to go about doing
>something like this?
>
>If I have to edit each file manually, and make the changes,
>I  might go insane!

I asked a similar question a few months ago, and a perl god, gamer,
and hiker responded with the following:

#Learn about
#
#    perl -00
#
#and the
#
#    s/foo/bar/s
#    s/foo/bar/m
#    s/foo/bar/sm
#
#flags.

Works great, although I think perl -0777 worked better for me.  As
far as I can tell, the latter three flags only work in perl 5.

Mike Linksvayer   http://www.au.com/ml/
Re: Find and Replace Perl function?
#56
Author: Zenin
Date: Sun, 28 Jan 1996 00:00
28 lines
1616 bytes
Jeff Dilcher <dilcher@shellx.best.com> wrote:
: I would like to change a block of text
	>snip<
: I am a little stumped about how to write a little perl 
: routine to do this.  Does Perl have a built in function
: that can identify and replace a whole block of lines of text?
	Could be, 'don't know enough of perl yet to tell you. :)

	But if you are *sure* that each line of this block is not
	found anywere else in the file, you could use a big stick
	approch like this:

#!/usr/bin/perl
while(<>) {
  chop;
  s/^complete line one of the original block$/line ONE\nTWO\n\THREE+ of new block/;
  s/^original line two$//;
  s/^original line three$//;
  s/^etc$//;
  print;
}
______
     /	Spelling mistakes?  Their couldn't be. -My modem is error correcting.
    /	
   /    Zenin@Best.com			---->>ROCKY HORROR ARCHIVE<<----
  /	 ___ 	__  o   __		   http://www.best.com/~zenin
 /	/___\ |/  \ | |/  \	       ftp://ftp.best.com:/pub/zenin/RHPS/
/_______\___  |	  | | |   |_______________________________________________
Re: Find and Replace Perl function?
#57
Author: Jeff Dilcher
Date: Mon, 29 Jan 1996 00:00
15 lines
1008 bytes
Thanks to all those who posted responses!
It appears there is a way to do this via command line
with Perl, but after playing around with the syntax for a while, 
I got frustrated.

I wound up using an old (but good) dos editor called q-edit
that I have.  It has some powerful macros, and it was able to
do the job very well.

Anyone have any idea if there is a windows editor with
decent macros built in?

Thanks again for everyones help,
-Jeff
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads