On 2/3/02 12:06, "Steven M. Klass" <[EMAIL PROTECTED]> wrote:
> Hi all
>
> I know there is a flip flop option but I'm not sure thats what I need..
> Here is what I want to do - and I have no idea how to do this.
>
> Basically I have a section of text that I am doing a search and replace
> operation. The problem is what if the search text doesn't exist - I still
> want to add it.
>
> So the logic is if it exists in the region replace it, if you can't find it
> add to to it
>
> if (/start/ .. /end/){
> s/^foo/bar/;
>
> }
> now what if foo didn't exist - bar still should be set!
>
> Any ideas?
While there still is input. While<FILE>
Match each line in an if else structure if ($_ =~ regex)
Then do something(replace).
Then you can use elsif to check if line is empty something like $_ == "\n"??
open (FILE, "filename");
While (<FILE>) {
if ($_ =~ /^tor/i) { # starts with tor
# Replace the line
} # end if
elsif ($_ == "\n") { # newline for empty lines
# Replace the "line"
} # end elsif
Else {
# Do nothing?
} # end else
} # end while.
That is at least one way.
I'm sure there are other and better ways to do this.
--
T.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]