in reply to Parsing bracket formatted file
Which outputs,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 } } } }
$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' } ];
|
|---|