I'd like to extend this to cover any level of nesting so that %a.deeply.nested.value would return $var{'a'}{'deeply'}{'nested'}{'value'} and the only thing I've come up with is a function that splits on the '.' and loops through the array to build a statement I can eval but I'm sure there has to be a more elegant way. If possible I'd like to avoid lookbehinds/lookaheads to keep the code portable to languages that don't support that. I'm also thinking I should I should be using $var{'foo'} instead of $var{'default'}{'foo'} so feel free to leave that out of any suggested solutions.$work =~ s{%(\w+)(?:\.(\w+))?}{ defined $2 ? $var{$1}{$2} : $var{default}{$1} }eg;
In reply to Recursively substitute against multidimensional hash by Maelstrom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |