in reply to Grabbing Structured multi line output from a file?

See Re: Parsing a config file with braces and nested braces, Re: Parsing a config file with braces and nested braces ( like json/yaml) , Re: Parsing a config file with braces and nested braces ... the threads they link and the parent threads
  • Comment on Re: Grabbing Structured multi line output from a file?

Replies are listed 'Best First'.
Re^2: Grabbing Structured multi line output from a file?
by Anonymous Monk on Apr 04, 2015 at 00:08 UTC
    yup, the sameness is the same
    my $FROM_CONFIG = qr{ (?<config> ^ \s* config (?<config_name> [^\r\n]+ ) [\r\n]+ ) | (?<closer> ^ \s* (?:end|next) \s* [\r\n]+ ) | (?<edit> ^ \s* (?i:edit) \s* "(?<edit_quoted> [^"]+ )" \s* [\r\n]+ ) | (?<set> ^ \s* (?i:set) \s+ #~ (?<set_key> \w+ ) (?<type> \w+ ) \s+ #~ "(?<set_val> [^"]+ )" #~ \s* (?<val> [^\r\n]++ ) [\r\n]+ ) | (?<UHOH> . ) }xms; my @stack = {}; while( $raw =~ m{$FROM_CONFIG}g ){ my $freeze = { %+ }; #~ dd( $freeze ); if( $freeze->{config} ){ my $new = {}; $stack[-1]->{ $freeze->{config_name} } = $new; push @stack, $new; }elsif( $freeze->{edit} ){ my $new = {}; $stack[-1]->{ $freeze->{edit_quoted} } = $new; push @stack, $new; }elsif( $freeze->{set} ){ $stack[-1]->{ $freeze->{type} } = $freeze->{val}; }elsif( $freeze->{closer} ){ pop @stack; } } dd( \@stack ); __END__