From: William James Date: 2005-01-30T05:10:50+09:00 Subject: Re: Why csv file processing is so slow? Improved version: % # Record separator. % RS = "\n" % % class String % # Set regexp for parse_csv. % # self is the field-separator % def is_fs % $csv_re = \ % %r{ "( (?: [^\\"] | \\")* )" | % '( (?: [^\\'] | \\')* )' | % ( [^#{self}]+ ) % }x % end % def parse_csv % raise "Method #is_fs wasn't called." if $csv_re.nil? % self.scan( $csv_re ).flatten.compact % end % end % % ','.is_fs % % # Set Ruby's input record-separator. % $/ = RS % % ARGF.each_line { | line | % p line.chomp.parse_csv % }