Parsing function arguments

G

glenlow

Apologies in advance if this is too newbie-ish. Couldn't find the
answer via googling or looking at various FAQ's.

Given a C function call in a string, how do I parse out the individual
arguments?

E.g.

"... func ((a+b)/c,d,e,f+(g+(h,i))) ..."

I need to get an array that is

("(a+b)/c","d","e","f+(g+(h,i))")

I know I can use extract_bracketed to get the outermost set of braces,
but how to I split out the arguments therein? (Note I can't just use
split on the comma since one of the comma's is embedded in a bracket
expression.

Cheers,
Glen Low, Pixelglow Software
www.pixelglow.com
 
P

Paul Lalli

Apologies in advance if this is too newbie-ish. Couldn't find the
answer via googling or looking at various FAQ's.

Given a C function call in a string, how do I parse out the individual
arguments?

E.g.

"... func ((a+b)/c,d,e,f+(g+(h,i))) ..."

I need to get an array that is

("(a+b)/c","d","e","f+(g+(h,i))")

I know I can use extract_bracketed to get the outermost set of braces,
but how to I split out the arguments therein? (Note I can't just use
split on the comma since one of the comma's is embedded in a bracket
expression.

Try taking a look at
perldoc -q delimited
"How can I split a [character] delimited string except when inside
[character]? (Comma-separated files)"

That generally deals with the case in which a CSV line has commas
embedded in quoted fields, but you should be able to modify the
solution (or use one of the two recommended modules) for your problem
as well...

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top