in reply to search for matching parentheses
Basically, it splits the line on commas and then makes sure the number of parenthesis in each splitted item match. If they don't, it splices the next line and recounts. So after you run your string through this code, the args array should be populated with the separated smaller strings.my @args = ( split/,/, $line ); my $size = $#args; # ugly hack to rejoin args that were incorrectly split (intern +al commas) for ( my $i = 0; $i < $size; $i++ ) { my $depth = 0; $depth++ while $args[$i]=~/[(]/g; $depth-- while $args[$i]=~/[)]/g; if ( $depth ) { splice ( @args, $i, 2, $args[$i].",".$args[$i+ +1] ); $i--; $size--; } }
Once you have the big string correctly split into the smaller strings, the regex is as simple as this:
If you really wanted to, you could just append this code at the bottom of the for loop.$args[$i] =~ (\w+)\(([^)]*)\) my $param = $1; my $stuffinsideparens = $2;
|
|---|