=head2 readConfig Read the configuration file specified, return a hash of the options read. =cut sub readConfig { my ($file) = ( @_ ); my %CONFIG; open( FILE, "<", $file ) or die "Cannot read config file '$file' - $!"; while (defined(my $line = ) ) { chomp $line; # Skip comments next if ( $line =~ /^([ \t]*)\#/ ); # Skip blank lines next if ( length( $line ) < 1 ); # Strip trailing comments. if ( $line =~ /(.*)\#(.*)/ ) { $line = $1; } # Find variable settings if ( $line =~ /([^=]+)=([^\n]+)/ ) { my $key = $1; my $val = $2; # Strip leading and trailing whitespace. $key =~ s/^\s+//; $key =~ s/\s+$//; $val =~ s/^\s+//; $val =~ s/\s+$//; # Store value. $CONFIG{ $key } = $val; } } close( FILE ); return( %CONFIG ); }