I ran into this problem awhile ago and wrote some code to handle it. It feels like a kludge, but it works:
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--; } }
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.

Once you have the big string correctly split into the smaller strings, the regex is as simple as this:

$args[$i] =~ (\w+)\(([^)]*)\) my $param = $1; my $stuffinsideparens = $2;
If you really wanted to, you could just append this code at the bottom of the for loop.

In reply to Re: search for matching parentheses by wojtyk
in thread search for matching parentheses by embirath

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.