As with most regular expressions, the following is assuming a whole lot. For example that there are not more embedded functions in the functions that occur inside the first function. Also that there are only 4 arguments (parameters?) passed to the first function. Lastly that there are no spaces between the argument and the comma. You might have to modify this to get the spacing (adding
\s in places and whatnot. Anyhow here is some code that might work for your purpose:
use strict;
use warnings;
while ( <DATA> ) {
my $string = $_;
if ( $string =~ /func[A-Za-z]\(
(func[A-Za-z]\([^\)]+\)|[^,]+) #looks for a function a
+nd if not found then
,(func[A-Za-z]\([^\)]+\)|[^,]+) #grab everything to the
+comma
,(func[A-Za-z]\([^\)]+\)|[^,]+)
,(func[A-Za-z]\([^\)]+\)|[^,]+)\)/x)
{
print "FOR STRING: $string",
'$1 = ',$1,$/,
'$2 = ',$2,$/,
'$3 = ',$3,$/,
'$4 = ',$4,$/,$/;
}
}
__DATA__
funca(1,2,3,4)
funca(funcH(A,B,C),2,3,4)
funca(1,funcH(A,B,C),3,4)
funca(1,2,funcH(A,B,C),4)
funca(1,2,3,funcH(A,B,C))
Updated:Removed some of the ugliness from the formatting in code.
-enlil
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.