Hi,
I have a script to rewrite a data file which is comma
delimited (sub openfile). Whenver there is a line return in a field, that
field
is wrapped with the double quote character.
I can't grab that field to write into the new data file properly.
In the pasted"sample.txt" file (bottom), line 2 and 3 are actually one
record.
I've attempted a work around (sub strip_wrap), trying to strip out any line
returns for
any field. This does not remove the line return.
Any suggestions
Below is the sub to open the Comma Delimited file:
sub openfile {
#work with each field in uploaded file
close DATA;
$Count2 = 0;
open (LIST, ">>$BaseDir/1_$foo");
if ($CField[5] ne "") {
$AdFile[$Count2] = $Ad;
## serial number $wum to renumber records
$wum = $Count2;
$Count2++;
&strip_wrap;
print LIST
qq!$wum|$CField[0]|$CField[1]|$CField[2]|$CField[3]|$CField[4]|$CField[5]|$C
Field[6]|$CField[7]|$CField[8]|$CField[9]|$CField[10]|$CField[11]|$CField[12
]|$CField[13]|$CField[14]|$CField[15]|$CField[16]|$CField[17]|$CField[18]|$C
Field[19]|$CField[20]|$CField[21]|$CField[22]|$CField[23]|$CField[24]|$CFiel
d[25]|0\n!;
Quote:
}
}
}
sub strip_wrap {
## need device to remove return from within a comma delimited field
$CField[0] =~ s/%0D%0A/ /go;
$CField[0] =~ s/\n/ /go;
$CField[0] =~ s/\r/ /go;
## ... and so on through all the fields
Quote:
}
--
sample.txt snip <<
Line 1: First Name,Last Name,Middle Name,Name,Nickname,E-mail Address,Home
Street,Home City,Home Postal Code,Home State,Home Country,Home Phone,Home
Fax,Mobile Phone,Personal Web Page,Business Street,Business City,Business
Postal Code,Business State,Business Country,Business Web Page,Business
Phone,Business Fax,Pager,Company,Job Title,Department,Office Location,Notes
Willow
Line 3: Ave",city,zip,state,Canada,phone,fax,cell,url,Bus
address,bcity,bzip,bprov,bcountry,,phone,fax,pager,ASM,btitle,bdept,office
num,test
Line 4: Adrian,Dan,,Adrian Dan,,,,,,,,(416) 245-1927,,,,,,,,,,,,,,,,,
Line 5: Adrian,Heaps,,Adrian
Line 6: Alan,Burt,,Alan Burt,,,,,,,,(416) 266-4682,,,,,,,,,,,,,,,,,
Quote:
>> end snip
Chris Bell
Tel: (416) 698-5763