in reply to Construct a data structure from a string

Not quite as sexy as BrowserUK's (though a bit clearer to me): here's my str2data.
sub str2data { my($string, $value) = @_; my $tmp; for my $part (reverse split /\./, $string) { undef $tmp; if ($part =~ /([^][]*?)\[(\d*?)\]/) { $tmp->{$1}[$2] = $value; $value = $tmp; } else { $tmp->{$part} = $value; $value = $tmp; } } return $value; }
It's single pass, but uses a tmp variable, which is somewhat clunky. Oh well.



Code is (almost) always untested.
http://www.justicepoetic.net/