469,916 Members | 2,263 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,916 developers. It's quick & easy.

parse string

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_CN T,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
Jul 19 '05 #1
2 7783
Vincent wrote:

$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_CN T,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"

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2
Gunnar Hjalmarsson wrote:
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.)

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Ram Laxman | last post: by
3 posts views Thread by Jon Davis | last post: by
3 posts views Thread by Mark | last post: by
8 posts views Thread by moondaddy | last post: by
5 posts views Thread by Navid Azimi | last post: by
5 posts views Thread by js | last post: by
29 posts views Thread by gs | last post: by
3 posts views Thread by Peter Duniho | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.