Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: another split question

by Roger (Parson)
on Sep 05, 2005 at 12:34 UTC ( [id://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"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found