in reply to splitting csv file and saving data
For parsing CSV files, don't re-invent the wheel and use Text::CSV instead. That will be able to parse each of your sample rows into four fields, and then getting the comma-separated values out of the 3rd column is as easy as my @vals = split /,/, $row->[2]; (see the module's synopsis for example code).
Update: As BrowserUk pointed out below, using a simple split is only appropriate if that field is never more than a plain comma-separated list, and if there is anything more complex going on in that field (quotes, escape characters, etc.) you'll have to use a more advanced method to parse it. If you wanted to play it safe, you could validate the format of that field before splitting it, e.g. $row->[2] =~ /^\d+(?:,\d+)*$/.
Hope this helps,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: splitting csv file and saving data
by BrowserUk (Patriarch) on Nov 03, 2016 at 11:04 UTC | |
by haukex (Archbishop) on Nov 03, 2016 at 11:26 UTC | |
by BrowserUk (Patriarch) on Nov 03, 2016 at 11:45 UTC | |
by haukex (Archbishop) on Nov 03, 2016 at 12:52 UTC | |
by Tux (Canon) on Nov 03, 2016 at 21:11 UTC | |
by BrowserUk (Patriarch) on Nov 03, 2016 at 21:53 UTC | |
by Anonymous Monk on Nov 03, 2016 at 11:27 UTC |