### returns the requested setting ### Used like so: my $name = getSetting('name'); ### Config file: name=Devin sub getSetting { my ($attr_to_get) = shift; # the attribute to get # opens and reads the config file, # returns a hash my %attrs = openCfgFile() ('your/path/to/config.file'); # return the requested attribute if it exists # otherwise, give them a big fat null return $attrs{$attr_to_get} ? $attrs{$attr_to_get} : "NULL"; } ### open, read, and return the hash. sub openCfgFile { my ($cfg) = shift; # the file parameter # open and read open CFG, "<", $cfg or die "File not found: $!"; my @settings = ; close CFG; my %values; # create the values hash foreach (@settings) { # loop through the file chomp; # remove endline characters (\n, \r....) s|#.+||; # remove comments s|"(.+?)"|$1|g; # (not working) allow whitespace for strings s|\s||; # remove whitespace my( $key, $val) = split /=/; # begin creating the hash, split the file on the "=" sign $values{$key}=$val; # create the hash key/values pairs } return %values; }