From: Robert Klemme Date: 2010-12-14T18:11:26+09:00 Subject: Re: Syntax error, want to use multiple variables in one line, copy mysql data On Mon, Dec 13, 2010 at 11:35 PM, K. V. wrote: > I'm completely new to Ruby and trying to do something pretty simple -- > run through the lines of a database and copy them using ruby. The data's > going from mysql to flockdb. The meat of the argument looks like this: > > res = mysql.query("SELECT source, target FROM old_data") > while row = res.fetch_row do >     flock.add(row[0], :follows, row[1]) >     end Maybe row looks different than you think. I would try this require 'pp' ... while row = res.fetch_row do pp row flock.add(row[0], :follows, row[1]) end > Now, I don't know what I'm doing wrong, though I'm sure it's easy, but > this never works. If I use only one of the variables (either row[0] or > row[1]) and make the other some constant (ie flock.add(1, :follows, > row[1]) it works fine. But if I use two, it never works. Even if I want > to check that they're integers, > > while row = res.fetch_row do >     Integer(row[0]), Integer(row[1]) >     end > > it fails. I have checked separately and they are, so that's not the > problem. These are the error messages that come back: This cannot work: 09:32:36 ~$ ruby19 -c < while row = res.fetch_row do > Integer(row[0]), Integer(row[1]) > end > CODE -:2: syntax error, unexpected ',', expecting keyword_end Integer(row[0]), Integer(row[1]) ^ 09:32:46 ~$ This is the error condensed to the simplest case: 09:32:46 ~$ ruby19 -ce 'a' Syntax OK 09:33:24 ~$ ruby19 -ce 'a,b' -e:1: syntax error, unexpected '\n', expecting '=' 09:33:27 ~$ You cannot have two expressions separated with comma - unless it's a list of arguments for a method call. > NoMethodError: undefined method `<' for [0]:Array >  from Probably the code expects a number and not an Array. Whether that's a bug in your code or in any of the used gems I cannot really tell ATM. > What I don't get is why it will add them separately, but won't add both > at the same time! Any help? All the tutorials seem to say this should > work just fine, that multiple variables is not a problem. :( Maybe that information is not in sync with the version of the software you have. Maybe authors of these gems can help. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/