<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:courier,monaco,monospace,sans-serif;font-size:12pt"><div style="font-family: courier,monaco,monospace,sans-serif; font-size: 12pt;"><span style="font-family: arial,helvetica,sans-serif;">You are right if it is well formated CSV file.</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">But I don't know if this is guaranteed. There is no document about it. I just rewrite an old </span><span style="font-family: arial,helvetica,sans-serif;">old uncommented/undocumented working scripts.</span><br style="font-family: arial,helvetica,sans-serif;"><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">The segment is just rewritten to make it little bit easier to read by replacing the embedded 'DEL' charters with a variable populate with function
 chr.</span><br><br><span style="font-family: arial,helvetica,sans-serif;">Below is the best I can do. It looks better to me and can run as two times faster than the old one does. I still cannot make out one-liner for it. Can anyone get ride of the first line?</span><br><font size="2"><br>&nbsp; my $leadingQ=""; $leadingQ='"' if /^"/; #save the leading quote if it is there<br>&nbsp; s/(?&lt;!,)"(?!(,|$))//g; # remove all double quote not next to comma or at the end of the line<br>&nbsp; print OUTF $leadingQ, $_;</font><br><br><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">----- Original Message ----<br>From: Steven Lembark &lt;lembark@wrkhors.com&gt;<br>To: Chicago.pm chatter &lt;chicago-talk@pm.org&gt;<br>Sent: Wednesday, October 24, 2007 2:14:48 PM<br>Subject: Re: [Chicago-talk] Removing Characters<br><br>
&gt; There must be better way for removing the double quote in a CSV file<br>&gt; optionally quoted by double quote.<br>&gt; What I did as below is ugly and not reliable. Could anyone provide
 one<br>&gt; beautify line?<br>&gt;<br>&gt;&nbsp;  $delimiter=chr(0227);<br>&gt;&nbsp;  s/^"/$delimiter/g;<br>&gt;&nbsp;  s/,"/,$delimiter/g;<br>&gt;&nbsp;  s/"$/$delimiter/g;<br>&gt;&nbsp;  s/",/$delimiter,/g;<br>&gt;&nbsp;  s/"//g;<br>&gt;&nbsp;  s/$delimiter/"/g;<br><br>You don't seem to want all of the quotes removed,<br>only the embedded ones. If the data is well-formatted<br>then the operation above will leave you with a bunch<br>of naked backslashes in the text:<br><br>&nbsp; "this is a \"double quoted\" text line"<br><br>becomes<br><br>&nbsp; "this is a \double quoted\ text line"<br><br>and you probably don't want the \d or \ in your<br>result.<br><br>If the real problem is that fate has handed you some<br>CSV data with embedded, un-escaped quotes then your<br>approach makes the most sense, but you'll have to<br>remove escaped quotes also:<br><br>&nbsp; s{ \\" }{}gx;<br><br>will strip the \" char's. You might prefer to replace<br>them with
 non-delimiting quotes, e.g.,<br><br><br>&nbsp; s{ \\" }{'}gx;<br><br>All of the CSV parsing modules assume "clean" CSV<br>source (oxymoron?) so if you need to clean up botched<br>data then some iterative approach is likely to be<br>what you need.<br><br>enjoi<br><br>-- <br>Steven Lembark&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  85-09 90th
 Street<br>Workhorse Computing&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Woodhaven, NY
 11421<br><a ymailto="mailto:lembark@wrkhors.com" href="mailto:lembark@wrkhors.com">lembark@wrkhors.com</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +1 888 359
 3508<br>_______________________________________________<br>Chicago-talk mailing list<br><a ymailto="mailto:Chicago-talk@pm.org" href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br><a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br></div><br></div></div></body></html>