Michael Sc wrote:
> Hello,
> I am a newbie with Ruby and I had a couple of questions while
> manipulating csv files.  How would I do a multiple column sort?  I have
> a file that needs to be sorted by the 3rd column, then 1st, then second.
> I understand how to do one sort for the csv file but I was unsure of how
> to do multiple.
> 
>  Also,How would I to do a percentage change between two numbers in a
> column?
> 
>  Thank you very much.  I know these are easy questions but I am still
> learning how to program in Ruby.

Come to think of it, I'd do the whole thing using FasterCSV. When 
available, I like to use a well known library where the hard work has 
already been done for me :)

require 'rubygems'
require 'faster_csv'

mycsv = FCSV.read("myfile.csv")

FCSV.open("output.csv","w") do |out|
  mycsv.sort{|a,b| [a[2],a[0],a[1]] <=> [b[2],b[0],b[1]]}.each |row|
    out << row
  end
end

-- 
Posted via http://www.ruby-forum.com/.