in reply to CSV file
To explain the regexp: the first ^ matches beginning of line, the ([^\,]*) captures the next contiguous set of non comma characters and places it in the first "numbered" variable ($1), the \,\s* steps over the first comma and any immediately trailing space, (update: that is now repeated to allow for the fact that there is a comma in the name field), the (.*) picks up everything thereafter placing it in the $2 variable and the $ matches with the end of the line.while( <FILE> ) { if ( /^([^\,]*\,\s*[^\,]*)\,\s*(.*)$/ ) { print "Name: $1\n"; print "Address: $2\n"; } }
-M
Free your mind
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: CSV file
by integral (Hermit) on Oct 31, 2005 at 15:20 UTC | |
by Moron (Curate) on Oct 31, 2005 at 15:38 UTC | |
|
Re^2: CSV file
by tirwhan (Abbot) on Oct 31, 2005 at 15:50 UTC | |
by Moron (Curate) on Oct 31, 2005 at 16:17 UTC | |
by tirwhan (Abbot) on Oct 31, 2005 at 16:51 UTC | |
by Moron (Curate) on Oct 31, 2005 at 17:00 UTC |