Hi,
I'm trying to read in a text file that's comma separated. Unfortunately, some of the data has carriage returns within the field before I get to newline and Perl thinks it an end of record.
How can I differentiate between carriage returns within the record and an "end of line" after each record?
Here's sample data:
110934,David,Johnson, 12 - hammers
1 - screw drivers
5 - box of 8d nails,december,RMA complete, not received, do not restock
110935,Ralph,Jones, 1 - CD drive,december,RMA sent,received, restock
110936,Angela,Smith, 500 socks,
1 - towel,october,RMA not sent, not received, restock
The number of fields are fixed, but the content is not.
I read the file in like this:
open (FILE, "$ccbookdb") or die "Cannot open ccbook database ($ccbookdb):$!\n";
while () {
chomp($in = <FILE>);
if ($in) {
($rma_number,$firstname,$lastname,$return_items,$date,$rma_log,$invlog,$restock_notify)=split(',',$in);
} else{ last; } # end of Database
}
I guess I could count the commas as I read in the data and ignore the carriage returns within the fields until I count up to the fixed number of commas in each record and then accept the newline but, I'm not sure how to approach that.
Any help would be much appreciated.
Rich
I'm trying to read in a text file that's comma separated. Unfortunately, some of the data has carriage returns within the field before I get to newline and Perl thinks it an end of record.
How can I differentiate between carriage returns within the record and an "end of line" after each record?
Here's sample data:
110934,David,Johnson, 12 - hammers
1 - screw drivers
5 - box of 8d nails,december,RMA complete, not received, do not restock
110935,Ralph,Jones, 1 - CD drive,december,RMA sent,received, restock
110936,Angela,Smith, 500 socks,
1 - towel,october,RMA not sent, not received, restock
The number of fields are fixed, but the content is not.
I read the file in like this:
open (FILE, "$ccbookdb") or die "Cannot open ccbook database ($ccbookdb):$!\n";
while () {
chomp($in = <FILE>);
if ($in) {
($rma_number,$firstname,$lastname,$return_items,$date,$rma_log,$invlog,$restock_notify)=split(',',$in);
} else{ last; } # end of Database
}
I guess I could count the commas as I read in the data and ignore the carriage returns within the fields until I count up to the fixed number of commas in each record and then accept the newline but, I'm not sure how to approach that.
Any help would be much appreciated.
Rich