in reply to Re: Construct a data structure from a string
in thread Construct a data structure from a string
$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;
|
|---|