On Sun, 25 Nov 2001 13:14:22 +0000, Simon Cozens wrote: >On Sun, Nov 25, 2001 at 02:32:34AM -0500, Angel Faus wrote: >> use Text::Balanced 'extract_bracketed'; > >Urgh. We need to work around this.
Can somebody fill me in exactly how this is supposed to behave? I think that this may come close: $_ = " { a { b } c { d } } { e { f } g } "; print "Extracted: '". extract_balanced($_) . "'\n"; print "Remains: '$_'\n"; sub extract_balanced { my $balance = 0; for(shift) { s/^\s+//; /^\{/ or die "bad block open"; while(/(\{)|(\})/g) { if($1) { $balance++; } else { # $2 --$balance or return substr($_, 0, pos, ""); } } die "Badly balanced" if $balance; } } This prints: Extracted: '{ a { b } c { d } }' Remains: ' { e { f } g } ' (p.s. for various reasons I am not capable of submitting an actual patch) -- Bart.