Pingu has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a small script for my running club's site to allow searchable race results.
The data is stored in a CSV format file which I split(/,/) on commas into an array. This is all great except some of the data fields contain commas which I want to keep:
The file looks something like this:
1,"FirstName","Surname","Running club, Country",hh:mm:ss 2,"etc.","etc.","Different club, same country",hh:mm:ss
The commas in the 4th field are to be kept, not split on.
I've tried:
while (<FP>) { s/"(.+?),(.+?)"/g; (@row) = split(/,/); }
but it doesn't work - it picks up the wrong commas. Can anyone help please?
I have a feeling that I need a non-backtracking pattern but I can't suss it.
Thanks folks,
Pingu
Edited 2001-05-28 by Ovid
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regexp nightmare
by petdance (Parson) on May 28, 2001 at 20:13 UTC | |
|
Re: Regexp nightmare
by Coyote (Deacon) on May 28, 2001 at 20:14 UTC | |
by tilly (Archbishop) on May 28, 2001 at 21:05 UTC | |
by shotgunefx (Parson) on May 29, 2001 at 00:29 UTC | |
by tilly (Archbishop) on May 29, 2001 at 06:31 UTC | |
by shotgunefx (Parson) on May 29, 2001 at 11:47 UTC | |
by Anonymous Monk on May 31, 2001 at 16:47 UTC | |
|
Re: Regexp nightmare
by JP Sama (Hermit) on May 28, 2001 at 20:24 UTC | |
|
Re: Regexp nightmare with CSV
by larryk (Friar) on May 29, 2001 at 00:29 UTC | |
|
Re: Regexp nightmare
by Pingu (Sexton) on May 28, 2001 at 20:14 UTC | |
|
Re: Regexp nightmare
by Pingu (Sexton) on May 28, 2001 at 20:17 UTC |