$inp = '"foo[1].bar.baz[0]", value: 123'; $inp =~ /^"(.*?)", value: (.*)$/; my $layout = $1; my $data = $2; while ($layout =~ s/(\[(\d+)\]|\.?(\w+))$//) { if ($3) { $data = { $3 => $data }; } else { $data = [ (undef) x $2, $data ]; } } print $data->{'foo'}->[1]->{'bar'}->{'baz'}->[0];
In reply to Re: Construct a data structure from a string
by TedPride
in thread Construct a data structure from a string
by saintmike
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |