budman has asked for the wisdom of the Perl Monks concerning the following question:
This is a bit tricky with all the differnt blocks. I started by splitting on newline into an array, then iterating the lines.my $contents = qq( create item "xxx" { remove entry "xxx" add entry "yy" "xxx" { item1=xxxx, item2=xxxx, } add diffenent entry "xxx" { item1=xxx, item2=xxxx, item3=xxx add subitem { item1=xxx, item2=xxx, item3=xxx } add subitem { item1=xxx, item2=xxx, } } another type { item1=xxx } with "xxx" } );
I remember doing something like this with recursion function when traversing directories. Any ideas what to try? Thanks.# I remove the C-style comments prior to this my @lines = split(/\n/,$list); my $level = 0; for (@lines) { print "$level:$_\n"; $level++ if /\{/; $level-- if /\}/; }
2006-07-23 Retitled by g0n, as per Monastery guidelines
Original title: 'parsing'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing balanced parentheses
by GrandFather (Saint) on Jul 23, 2006 at 04:05 UTC | |
by budman (Sexton) on Aug 03, 2006 at 07:28 UTC | |
Re: Parsing balanced parentheses
by rodion (Chaplain) on Jul 23, 2006 at 11:32 UTC | |
Re: Parsing balanced parentheses
by planetscape (Chancellor) on Jul 23, 2006 at 05:09 UTC | |
Re: Parsing balanced parentheses
by eyepopslikeamosquito (Archbishop) on Jul 23, 2006 at 12:11 UTC | |
by rodion (Chaplain) on Jul 23, 2006 at 17:10 UTC | |
Re: Parsing balanced parentheses
by fmerges (Chaplain) on Jul 23, 2006 at 10:44 UTC | |
Re: Parsing balanced parentheses
by I0 (Priest) on Jul 24, 2006 at 04:53 UTC |