From: Hugh Sasse Staff Elec Eng Date: 2004-10-26T01:26:26+09:00 Subject: CSV, string handling. Have I discovered a bug in CSV? If data is read in and it is quoted, when it is written out it is not quoted. My own feeling about this is that it should be easy to rewrite a format read in. I am taking the approach to reading and writing described on page 663 of the New Pickaxe. Should I be doing something else? I have packaged this as a very simple shar WITH NO CHECKS to demonstrate that there are no transcription errors on my part, and for ease of unpacking for those willing to verify the behaviour, and for the reason that simple shars are human-readable. Thank you, Hugh #!/bin/sh # This is a shell archive (produced by GNU sharutils 4.2.1). # To extract the files from this archive, save it to some FILE, remove # everything before the `!/bin/sh' line above, then type `sh FILE'. # # Made on 2004-10-25 17:17 WEST by . # Source directory was `/home/hgs/progs/ruby/CSV'. # # existing files WILL be overwritten # This format requires very little intelligence at unshar time. # "echo", "mkdir", and "sed" may be needed. # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 215 -rwxr--r-- inout.rb # 73 -rw-r--r-- input.dat # 53 -rw-r--r-- output.dat # echo=echo if mkdir _sh06942; then $echo 'x -' 'creating lock directory' else $echo 'failed to create lock directory' exit 1 fi # ============= inout.rb ============== $echo 'x -' extracting 'inout.rb' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'inout.rb' && X#!/usr/local/bin/ruby -w Xrequire 'csv' X# vim:set sw=2 et: X Xopen('output.dat','w') do |output| X CSV::Writer.generate(output, ?,) do |out| X CSV.open('input.dat','r') do |row| X out << row X end X end Xend SHAR_EOF : || $echo 'restore of' 'inout.rb' 'failed' # ============= input.dat ============== $echo 'x -' extracting 'input.dat' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'input.dat' && X"I","consist","of","strings","only" X"All","strings","are","in","quotes" X SHAR_EOF : || $echo 'restore of' 'input.dat' 'failed' # ============= output.dat ============== $echo 'x -' extracting 'output.dat' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'output.dat' && XI,consist,of,strings,only XAll,strings,are,in,quotes X SHAR_EOF : || $echo 'restore of' 'output.dat' 'failed' rm -fr _sh06942 exit 0