Am 01.08.2013 17:00, schrieb Talal B.:
> Hi Guys,
> 
> I'm trying to use a ruby script to read a column of data from a single
> text file or csv and put it into an array which i can print out and also
> append "varchar," after each hash entry.
> 
> For example
> 
> if i had
> 
> test
> 12
> 312
> soon
> fast
> bob
> 
> I want it to turn into
> 
> bob varchar, 12 varchar, 312 varchar, soon varchar, fast varchar, bob
> varchar
> 
> How would this be possible?

One way to do it:

$ cat data.txt
test
12
312
soon
fast
bob

$ irb
2.0.0-p247 :001 > data = File.readlines('data.txt')
 => ["test\n", "12\n", "312\n", "soon\n", "fast\n", "bob\n"]
2.0.0-p247 :002 > data.map! {|entry| "#{entry.chomp} varchar" }
 => ["test varchar", "12 varchar", "312 varchar", "soon varchar", "fast
varchar", "bob varchar"]
2.0.0-p247 :003 > data.join(', ')
 => "test varchar, 12 varchar, 312 varchar, soon varchar, fast varchar,
bob varchar"


Regards,
Marcus


-- 
GitHub: https://github.com/stomar/
PGP:    0x6B3A101A