#!/usr/bin/perl -w
use strict;
 
my ($cfgfile, $key, $default);

unless (@ARGV > 0) { die "usage: $0 <key> [default return value]" }
($cfgfile, $key, $default) = @ARGV;

open(FILE, $cfgfile) or die "Couldn't open $cfgfile";

while (<FILE>) {
    if (/^$key:/) {
        #print "found key $key\n";
        eval "s/^$key:\\s+//"; # remove the key: and whitespace
        s/\s+#(\w|\W)*//;      # remove space, #, trailing whitespace and chars
        s/\#(\w|\W)*//;        # remove # and trailing whitespace and chars
        s/\s+$//;              # remove trailing whitespace
        chomp();
        print "$_";
        exit 0;
    }
}
if ($default) {
    print "$default\n";
    exit 0;
} else {
    #print "ERROR\n";
    exit -1;
}
