Rhodium has asked for the wisdom of the Perl Monks concerning the following question:
I have read in this file as a whole. Now I want to do a search and replace only on a particular block, namely the DESCRIPTION block. All blocks start with a "*KEYNAME" and end with a "*END". I want to only deal with the *DESCRIPTION block.; This is a comment starts with semicolon *DESCRIPTION keyword = foo ; keyword2 = bar *END ; *OPERATION blah bla *END
So the questions start..
So let's talk code..
Edit by dws for tag cleanup#!/bin/perl -w # # Slurp in the file open (RUNSET, text.txt} ) || die "Can't access test\n"; my $page = do { local $/, <RUNSET> }; close RUNSET; # Now How do I selectively find the DESCRIPTION block to # modify it. Look out for the comments.. Within the # DESCRIPTION block I could care less about comments # Assuming I have the DESCRIPTION block do a search # What if i Didn't find it, add it at very end before # the *ENDS.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Search for a BLOCK of text and selectively replace
by PrakashK (Pilgrim) on Mar 22, 2002 at 05:40 UTC | |
|
Re: Search for a BLOCK of text and selectively replace
by krazken (Scribe) on Mar 22, 2002 at 04:59 UTC | |
|
Re: Search for a BLOCK of text and selectively replace
by Ri-Del (Friar) on Mar 22, 2002 at 05:41 UTC | |
by dmmiller2k (Chaplain) on Mar 22, 2002 at 07:07 UTC | |
by Rhodium (Scribe) on Mar 22, 2002 at 14:30 UTC | |
|
Do this using regular expressions (my solution..)
by flocto (Pilgrim) on Mar 22, 2002 at 06:05 UTC | |
|
Re: Search for a BLOCK of text and selectively replace
by aersoy (Scribe) on Mar 22, 2002 at 18:06 UTC |