Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: split string by comma

by BrowserUk (Pope)
on Jan 10, 2012 at 23:35 UTC ( #947257=note: print w/replies, xml ) Need Help??


in reply to split string by comma

If your sample text reflects a true indication of your needs -- it often doesn't -- then you could use:

$s = '1945,"4,399.00",938,1/10/2012';; print for $s =~ m[("[^"]+"|[^,]+),]g;; 1945 "4,399.00" 938

For data that conforms to the original formulation of 'csv' data, rather than the bastardized corruption of that once de-facto standard that is now foisted upon us, this is all you need, and it usually runs several times faster than Text::CSV* modules.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://947257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2020-10-25 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?