So far I have a text configuration file with variables in it:
foo=something
bar=${foo}
When processing in Perl, I replace the variables with the following expression:
s/(?<!\\)\$\{\s*([^\}\s]+(\s+[^\}\s]+)*)\s*\}/_replacement( $1 )/ge;
where _replacement () knows how to look for existing values.
Now I would like to extend the syntax of the text file so that I can do it recursively, for example:
platform=x86
foo_x86=somepc
foo_arm=somedevice
bar=${foo_${platform}}
where, when processing the last line, "$ {platform}" is first replaced with "x86", and the resulting "$ {foo_x86}" is replaced with "somepc".
I'm having trouble expanding my regex: I can't find a way to match} with the correct {. (Greedy will not work because the string may be "$ {a} $ {b}" and the unwanted one will not match.)
Ideas?