in reply to Re: Splitting a line on just commas
in thread Splitting a line on just commas
This of course fails in the following cases, because it's looking for the space after the comma:
a,b,"hey,you",etc a, b, "hey, you", etc
Which is why it was qualified with "if your sample is indicative". A more general solution can be found by focusing on the fields themselves, rather than the commas:
@fields = $s =~ /("[^"]*"|[^,]*),/gc; $lastfield = $s =~ /\G(.*)/; push @fields, $lastfield;
But even that has no provision for placing a quotation mark inside a quoted string, and I'm sure there are other things I missed. The problem is hairier than it looks, hence, Text::CSV or Text::CSV_XS is best.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Splitting a line on just commas
by BrowserUk (Patriarch) on Jun 14, 2010 at 17:11 UTC |