$r = $1 ? \$$r->{$1} : \$$r->[$2] while $string =~ /\G(?:\.?(\w+)|\[(\d+)\])/g;Note - I'm assuming that the input is known to be valid and that $1 can never be '0'.
Given I'm already assuming $string is well formed the regex is much more complex than it needs to be.
$r = $1 ? \$$r->{$1} : \$$r->[$2] while $string =~ /(\w+)|\[(\d+)/g;
In reply to Re^2: Construct a data structure from a string
by nobull
in thread Construct a data structure from a string
by saintmike
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |