http://qs1969.pair.com?node_id=11147096

Stilgar has asked for the wisdom of the Perl Monks concerning the following question:

I have a bunch of files I need to pull into a data structure hash of hashes. The overall record is enclosed with brackets and is composed of KEY, VALUE pairs. The KEY is always text followed by a space, then the VALUE, which can be simple text or another bracketed sub-record. For example

sys ecm cloud-provider /Common/aws-ec2 { description "The aws-ec2 parameters" property-template { account { } availability-zone { valid-values { a b c d } } instance-type { valid-values { t2.micro t2.small t2.medium } } region { valid-values { us-east-1 us-west-1 } } } }

That's a simple one and there are arbitrarily nested records. It was originally formatted with newlines and spaces as well but that's been removed. So, for example, KEYS are usually separated by a newline, but sometimes just spaces. It's always some type of whitespace. I've been trying to parse it out with regex'es after slurping the file in a scalar, then tried writing a recursive function to do it. Any advice on the best way to approach it would be greatly appreciated!