What I want is a subroutine that matches a set of nested parens. That is, what I'd like is:
and have $parens end up with "a a (a a)(a a)" and $rest be "(b b(b)b b)" I seem to recall doing something like this when I was an undergraduate and it involved something like counting parens [that is, count +1 for a ( and -1 for a ) and you've got the first balanced set when the count == 0. Is there a more elegant way to do it in Perl?$str = "(a a (a a)(a a))(b b(b)b b)" and have my ($parens, $rest) = match($str) ;
In reply to Matching nested parens by BernieC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |