parse string

V

Vincent

hi,

can anyone help ?

$text=qq(a11.CLEC_ID ACNA,
count(1) PR402RSSSDEN,
sum(Decode(a11.CMPINTV-a11.APPINTV,0,a11.COMP_MAC_DY_CNT,a11.LEAST_DELAY_DAYS))
PR402RSSSNUM,
(STDDEV(Decode(CMPINTVa11.APPINTV,0,COMP_MAC_DY_CNT,LEAST_DELAY_DAYS))
* 1.0) PR402RSSSSD)

how can i parse this comma-separated string
but should not split if comma is inside parentheses() ?

thanks for help

vincent
 
G

Gunnar Hjalmarsson

Vincent said:
$text=qq(a11.CLEC_ID ACNA,
count(1) PR402RSSSDEN,
sum(Decode(a11.CMPINTV-a11.APPINTV,0,a11.COMP_MAC_DY_CNT,a11.LEAST_DELAY_DAYS))
PR402RSSSNUM,
(STDDEV(Decode(CMPINTVa11.APPINTV,0,COMP_MAC_DY_CNT,LEAST_DELAY_DAYS))
* 1.0) PR402RSSSSD)

how can i parse this comma-separated string
but should not split if comma is inside parentheses() ?

One approach is to replace those commas you want to split on with some
unique character, and then split:

$text =~ s/(\([^\)]+\))|,\s*/$1 or "\0"/eg;
my @text = split /\0/, $text;

But don't forget to study the applicable Q/A in the Perl FAQ:

perldoc -q "except when inside"
 
G

Gunnar Hjalmarsson

Gunnar said:
One approach is to replace those commas you want to split on with
some unique character, and then split:

$text =~ s/(\([^\)]+\))|,\s*/$1 or "\0"/eg;
my @text = split /\0/, $text;

It just struck me that this method isn't reliable, since there are
nested parentheses. You'd better go for a module. (See the FAQ.)
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top