in reply to Parsing a config file with braces and nested braces

Speaking of Re: Parsing a config file with braces and nested braces ( like json/yaml) and Re: Parsing a config file with braces and nested braces this works
#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; use 5.010; #~ use v5.10.0; my $raw = ' bob { ed { larry { rule5 { option { disable-server-response-inspection no; } tag [ some_tag ]; from [ prod-L3 ]; to [ corp-L3 ]; source [ any ]; destination [ any ]; source-user [ any ]; category [ any ]; application [ any ]; service [ any ]; hip-profiles [ any ]; log-start no; log-end yes; negate-source no; negate-destination no; action allow; log-setting orion_log; } rule6 { option { disable-server-response-inspection no; } tag [ some_tag ]; from [ prod-L3 ]; to [ corp-L3 ]; source [ any ]; destination [ any ]; source-user [ any ]; category [ any ]; application [ any ]; service [ any ]; hip-profiles [ any ]; log-start no; log-end yes; negate-source no; negate-destination no; action allow; log-setting orion_log; } } } } '; my $FROM_CONFIG = qr{ (?<OBJECT_OPEN> ^ \s* (?<NAME> \w+ ) \s* \{ \s* [\r\n]+ ) | (?<OBJECT_CLOSE> ^ \s* \} \s* [\r\n]+ ) | (?<KEYVAL> ^ \s* (?<KEY> [\w\-]+ ) \s+ (?<VAL> [^\r\n\{;]+ ) ; \s* [\r\n]+ ) | (?<UHOH> . ) }xms; my @stack = {}; while( $raw =~ m{$FROM_CONFIG}g ){ ## dd( \%+ ); ## push @stack, { %+ }; my $freeze = { %+ }; if( $freeze->{OBJECT_OPEN} ){ my $new = {}; $stack[-1]->{ $freeze->{NAME} } = $new; push @stack, $new; }elsif( $freeze->{OBJECT_CLOSE} ){ pop @stack; }elsif( $freeze->{KEYVAL} ){ $stack[-1]->{ $freeze->{KEY} } = $freeze->{VAL}; } } dd( \@stack ); __END__