#!/usr/bin/perl -w
###############################################################################
# FILE:		fixconf.pl
# PURPOSE:	remove comments from an apache httpd.conf file
#
# AUTHOR:	Denice Deatrich
# DATE:		Aug 00
#
# NOTES:	
###############################################################################


## needed packages
use strict;
no strict 'vars';

## process cmd-line args
$#ARGV != 0 && die( "USAGE: $0 APACHE_CONFIG_FILE\n" );
$f = $ARGV[0];

## generate the new filename
$newconf = ">" . "$f" . ".new";   ## for the new config file

## open config file from command line and read the lines into memory
open( FILE, $f ) || die( "cannot open $f: $!\n" );
@lines = <FILE>;
close( FILE ) || die( "cannot close $f: $!\n" );

## open new config file
open( FILE, $newconf ) || die( "cannot open $newconf: $!\n" );

## strip out general comments, leaving behind '^##' && '^#[alphanum]'
foreach $line (@lines) {
##  if( $line !~ /^[ |\t]*#[ |\t]*/ && $line !~ /^[ |\t]*$/ ) {
  if( $line !~ /^[ |\t]*[#][ |\t\n]+/ ) { ## then echo into new file
    printf( FILE "%s", $line );
  }
}
close( FILE ) || die( "cannot close $newconf: $!\n" );
printf( "Your new config file is called %s.new\n", $f );