Creating Arrays

Dear All,<?xml:namespace prefix = o ns =
“urn:schemas-microsoft-com:office:office” />

Please forgive me if this email is a bit simple, but I am new to ruby
and object orientated programming pretty much and just looking for a few
tips from the experts.

I have a .csz file created from a spreadsheet which contains 666 rows
and 19 columns. What I would like to do is read the csz file into an
array in ruby and store that array as a set of columns and rows (like in
excel). Once I have achieved this, I will be making some updates to all
the figures within the Array.

At the moment my code looks like this:

print “Importing Planning Sheet: 2004_extrap_Planning_Data\n”

filepath = ‘Q:\TECH2006\DBA\02_LU\Final TAGM 2007
(working)\TAGM_666_Current_FROM
G_DRIVE\2004\2004_extrap_Planning_Data.csv’

Input_file = File.new(filepath, ‘r’)

puts “READING THE FILE”

fields = Array.new

while ( !Input_file.eof )

        line = Input_file.gets



        line.each(',') { |this_record|

                    fields << this_record.chomp(",").strip()

                     }

Input_file.each { |line| }

End

What I understand is happening is that I am reading my file into a new
Ruby file called “Input_file” and then I am creating a new Array called
“fields” and I am loading the new file into the fields array but
removing the commas using the chomp in each line. Unfortunately it isn’t
working!

My question is basically how do I do what I want to do?.. It is
difficult for a new starter but I suspect you guys would know it inside
out!

Any tips would be greatly appreciated!

Cheers!

  • John

#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared
by MailMarshal
#####################################################################################

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs