On Jun 20, 9:10 am, [EMAIL PROTECTED] (Ravi Malghan) wrote:
> Hi: I am trying to extract some stuff from a string and not getting the 
> expected results. I have looked 
> throughhttp://www.perl.com/doc/manual/html/pod/perlre.html and can't seem to 
> figure this one out.
> I have a string which is a sequence of words and each item is comma seperated
> field1, lengthof value1, value1,field2, length of value2, 
> value2,field3,length of value3, value3 and so on
> After each field name I have the length of the value
> I want to split this string into an array using comma seperator, but the 
> problem is some values have one or more commas within them.
> so for example my string might look like this
> $origString = "EMPLID,4,9066,USERID,7,W3LWEB1,TEXT,54,This is a test note, 
> with some commas, and more commas,ADDR,3515421 Test Lane, Rockville, MD, 
> USA,ESCALATION-LVL,1,0"
> My current code goes character by character and constructs what I want. But 
> is very slow when this string gets large.
> TIA
> Ravi



> I want to split this string into an array using comma seperator, but the 
> problem is some values have one or more commas within them [..]
<snip>
> My current code goes character by character and constructs what I want. But 
> is very slow when this string gets large.
            Post your code or relevant portion.  Otherwise we might
repeating here stuff what you've done or tried already.

           Is there any way you can use another delimiter such as
tildes ~ or something? If you tweak to accept other delimiters that
would be easier to treat.  If you cannot, you could use regex to find
the next alpha_num character of the string and put those into an
array,

     \w  Match a "word" character (alphanumeric plus "_")
     \W  Match a non-word character
    \b  Match a word boundary
    \B  Match a non-(word boundary)

 or find out exactly the number of commas it may have and weed them
out...
     *      Match 0 or more times
    +      Match 1 or more times
    ?      Match 1 or 0 times
    {n}    Match exactly n times
    {n,}   Match at least n times
    {n,m}  Match at least n but not more than m times
   etc..

         But again, post your code so we don't overlap...


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to