in reply to Parsing file and removing a section
my $line; while ($line = <CONF>) { my $string; # check for start of virtual host block if ( $line =~ /^\s*\<VirtualHost/ ) { $string = $line; #no chomp # read in the enter virtualhost block... do { $line = <CONF>; $string = $string . $line; } until $line =~ /^s*\<\/VirtualHost\>/; # Find the server name $string =~ /ServerName\s+(.*)\s/; # Ignore it if necessary...you can add a number of checks here # including multple servers that you want to ignore. if ( $1 ne "my.domain.here" ) { print <CONF.NEW> $string; } } else { # if not a virtual server line, just pass it through. print <CONF.NEW> $line; } }
|
|---|