Perl Script: Deleting a block of text

Say I have a file with a bunch of config blocks (see below) in a file. If I send a variable to the function, how can I remove that block of text?

define host{
   host     abc
   description   testserver
}

define host{
   host     xzy
   description    prodserver
}

So in the example above, I want to remove host name "abc," I want the config block for "abc" host gone from the file.

Hi.

As usual, lots of ways to do this; here's a simple one:

#!/usr/bin/perl

# @(#) p1	Demonstrate record separator for deleting stanzas.

use warnings;
use strict;

use English qw( -no_match_vars );

my($debug);
$debug = 0;
$debug = 1;

my($sep) = "}";
$INPUT_RECORD_SEPARATOR = $sep;

my($delete) = "abc";

while ( <> ) {
  next if /$delete/;
  print;
}

exit(0);

Assuming your data file is on "data1", this produces:

% ./p1 data1


define host{
   host     xzy
   description    prodserver
}

See perldoc perldoc for how to find details of operations ... cheers, drl

awesome ... now i can move on w/ the rest of the code!

thx a lot. Question, what does this line do?

use English qw( -no_match_vars );

Hi.

perldoc -f use
perldoc English

cheers, drl