in reply to Re: problems parsing CSV
in thread problems parsing CSV
How's this? And no, I haven't tested it exhaustively nor compared it to Text::CSV.
#!/usr/bin/perl
use strict;
use warnings;
local $/;
my $data = <DATA>;
while( $data =~ m{ (?: \" ( .*? (?: \"\" .*? )*? ) \" | ( [^,]*? ) ) ( \, | \n ) }msxg ){
my $item = $1;
if( not defined $item ){
$item = $2;
}
my $nl = $3;
print "\t«$item»\n";
if( $nl eq "\n" ){
print '-' x 40, "\n";
}
}
__DATA__
stuff,"more","foo (1994 "bar" only)",1234,1988,3.0,""
a,b,c,
x,y
"a","foo""bar",test
a,"foo"bar",test
</code>
|
|---|