in reply to RE: Config file parser
in thread Config file parser
One quibble-- if you had a non-word character in there, like so:
Then it would turn it intofoo=hello fruit=apple foo.bar=tunafish color=red baz=$foo.bar
instead ofbaz=hello.bar
baz=tunafish
Still, it's a powerful technique, and I like it. It gives config-files a Makelike capability. You could say:
and then get:SCRIPT_DIR=/usr/local/scripts MAIN_SCRIPT=$SCRIPT_DIR/main_script.pl
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):
That way, we could handle my previous example like so:$value =~ s/\$ ( {\.+?} | \w+)/$config{$2}/gx;
foo=hello fruit=apple foo.bar=tunafish color=red baz=${foo.bar}
|
|---|