Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > parse string

Reply
Thread Tools

parse string

 
 
Vincent
Guest
Posts: n/a
 
      12-16-2003
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
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-16-2003
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

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-16-2003
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
Parse / Convert string - i give up Lelle ASP .Net 1 03-24-2005 09:05 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
Is there a buit-in method to parse a STYLE attribute string? Henri ASP .Net 2 11-29-2004 02:59 AM
Perl - Parse UNC Path in a string variable Kevin Joseph Perl 5 08-13-2004 11:56 AM



Advertisments