Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: another split question

by Roger (Parson)
on Sep 05, 2005 at 12:34 UTC ( #489213=note: print w/ replies, xml ) Need Help??


in reply to another split question

I just realised that is not what OP is looking for...
There is the hard way...

use strict; use Data::Dumper; while (<DATA>) { chomp; my @rec; foreach (split /"(.*?)(?:(?<!")"(?!")|(?<="")"(?!"))|,/) { s/""/"/g, push @rec, $_ if $_ } print Dumper(\@rec); } __DATA__ 1,"Hello, world",This is good,2 121212,"Simpson, Bart",Springfield,"Roger" 121212,"2"" tape, ""white",springfield,"Roger" 121212,"Simpson "", Bart",Springfield,"Roger" 121212,"2""",springfield,"Roger"

And there is the easy way...
use Text::CSV_XS; use Data::Dumper; my $csv = Text::CSV_XS->new(); while (<DATA>) { chomp; my $status = $csv->parse($_); my @rec = $csv->fields(); print Dumper(\@rec); } __DATA__ 1,"Hello, world",This is good,2 121212,"Simpson, Bart",Springfield,"Roger" 121212,"2"" tape, ""white",springfield,"Roger" 121212,"Simpson "", Bart",Springfield,"Roger" 121212,"2""",springfield,"Roger"


Comment on Re: another split question
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-06 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (84 votes), past polls