Syntax error I am getting while csv operations

Hi,

I am keep getting an error from the below code.

hash = { 'A' => [ 'v', 'x', 'y' , 'z' ] , 'B' => [ 'm', 'n' , 'o' ] }
CSV.open ('/home/kirti/workspace/Ruby/a.csv',"w", :headers => true) do

csv>

   hash.each do |k, v|
      csv[k]=v
   end
end
# ~> -:2: syntax error, unexpected ',', expecting ')'
# ~> ...me/kirti/workspace/Ruby/a.csv',"w", :headers => true) |csv|
# ~> ... ^
# ~> -:2: syntax error, unexpected ',', expecting end-of-input
# ~> ...irti/workspace/Ruby/a.csv',"w", :headers => true) |csv|
# ~> ... ^

Can anyone tell me where wrong I did ?

···

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

"CSV.open (" <<< remove the " "

···

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

change
CSV.open ('/home/kirti/workspace/Ruby/a.csv',"w", :headers => true) do
to
CSV.open('/home/kirti/workspace/Ruby/a.csv',"w", :headers => true) do

···

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

Hans Mackowiak wrote in post #1134441:

"CSV.open (" <<< remove the " "

I don't understand :frowning:

···

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

Hans Mackowiak wrote in post #1134449:

change
CSV.open ('/home/kirti/workspace/Ruby/a.csv',"w", :headers => true) do
to
CSV.open('/home/kirti/workspace/Ruby/a.csv',"w", :headers => true) do

Thanks friend.. Lots of code today.. My eyes were not working at that
time.. So... :slight_smile:

···

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

Hans Mackowiak wrote in post #1134441:

"CSV.open (" <<< remove the " "

I don't understand :frowning:

I believe Hans means that you need to remove the space between CSV.open and the opening parenthesis. The space there is significant to Ruby:

  ~ ∙ irb --simple-prompt
  >> handle = File.open ('.bash_profile', 'rb')
  SyntaxError: (irb):1: syntax error, unexpected ',', expecting ')'
  handle = File.open ('.bash_profile', 'rb')
                                      ^
  (irb):1: syntax error, unexpected ')', expecting end-of-input
    from /Users/mike/.rubies/ruby-2.1.0/bin/irb:11:in `<main>'
  >> handle = File.open('.bash_profile', 'rb')
  => #<File:.bash_profile>

Hope this helps,

Mike

···

On Jan 26, 2014, at 12:46 PM, Arup Rakshit <lists@ruby-forum.com> wrote:

--

Mike Stok <mike@stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.

Mike Stok wrote in post #1134452:

Hans Mackowiak wrote in post #1134441:

"CSV.open (" <<< remove the " "

Yes, Mike that worked. Thanks for your reply. I got it from Hans's
second reply although.

···

On Jan 26, 2014, at 12:46 PM, Arup Rakshit <lists@ruby-forum.com> wrote:

  >> handle = File.open('.bash_profile', 'rb')
  => #<File:.bash_profile>

Hope this helps,

Mike

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