In the spirit of TIMTOWTDI, I figured the record looked similar enough to a Perl data structure to warrant some gratuitous use regular expressions. So I came up with the following:
use strict; use warnings; # parse the follow text block (as given) - not trying # to make a general solution here... my $text = do { local $/; <DATA> }; $text =~ s/^(.+)\{/qw|$1|,\n\r{/; $text =~ s/ \{/ => {/g; $text =~ s/{(.+)}/\[qw\/$1\/\]/g; $text =~ s/}/},/g; $text =~ s/]/],/g; $text =~ s/(\w+-\w+) =/'$1' =/g; $text =~ s/ (\w+) "(.+)"/ $1 => "$2",/; $text = sprintf qq{[%s]}, $text; my $record1 = eval $text; require Data::Dumper; print Data::Dumper::Dumper($record1); __DATA__ 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 } } } }
Which outputs,
$VAR1 = [ 'sys', 'ecm', 'cloud-provider', '/Common/aws-ec2', { 'property-template' => { 'account' => [], 'region' => { 'valid-values' => [ + 'us-east-1', + 'us-west-1' ] }, 'instance-type' => { 'valid-value +s' => [ + 't2.micro', + 't2.small', + 't2.medium' + ] }, 'availability-zone' => { 'valid-v +alues' => [ + 'a', + 'b', + 'c', + 'd' + ] } }, 'description' => 'The aws-ec2 parameters' } ];

In reply to Re: Parsing bracket formatted file by perlsherpa
in thread Parsing bracket formatted file by Stilgar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.