in reply to How to delete conetents between two strings.
This smells a bit like homework but could be very usful to any random sysadmin, too. I'm going to put the actual code in a spoiler tag and hope you choose honorably based on your situation.
my $remove = 0; while ( <> ) { if ( $remove ) { # don't print $remove = 0 if /^\*\*End Temp \*\*/; } elsif ( /^\*\*Temp\*\*/ ) { $remove = 1; } else { print $_; } }
Another way is to slurp the data and use a multi-line regex replacement. That won't take too much memory if there aren't too many lines (for some values of "too much" and "too many"). Implementation is left as an exercise.
There are likely many more exotic ways to handle this as well, but one or the other of the ones already mentioned should work for you.
|
|---|