in reply to RE: Config file parser
in thread Config file parser

Neat and powerful.

One quibble-- if you had a non-word character in there, like so:

foo=hello fruit=apple foo.bar=tunafish color=red baz=$foo.bar
Then it would turn it into
baz=hello.bar
instead of
baz=tunafish

Still, it's a powerful technique, and I like it. It gives config-files a Makelike capability. You could say:

SCRIPT_DIR=/usr/local/scripts MAIN_SCRIPT=$SCRIPT_DIR/main_script.pl
and then get:
MAIN_SCRIPT=/usr/local/bin/scripts/main_script.pl

You could probably answer the above objection by putting bracket support into it, like so (untested):

$value =~ s/\$ ( {\.+?} | \w+)/$config{$2}/gx;
That way, we could handle my previous example like so:
foo=hello fruit=apple foo.bar=tunafish color=red baz=${foo.bar}