in reply to Construct a data structure from a string

#! perl -slw use strict; use Data::Dumper; my $string = "foo[1].bar.baz[0] = 123"; my @bits = split '\.| = ', $string; my $data = pop @bits; m/(\w+)(?:\[(\d+)\])?/ and $data = { $1 => $2 ? [ (undef) x $2, $data ] : $data } for reverse @bits; print Dumper $data; __END__ P:\test>393104 $VAR1 = { 'foo' => [ undef, { 'bar' => { 'baz' => '123' } } ] };

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon