How can skip the lines while using CSV by the option (:skip_lines)

Code I tried :

require 'csv'

text = <<-STR
Ram earns $2500 per month
Arup earns $5000 per month
Ayan earns $42,000 per mnth
Anup earns $225000 per month
Deba earns $450000 per month
STR

File.write("test.csv",text)

File.foreach('test.csv',:skip_lines =>
/^[^0-9]+(\d{5,6})[^0-9]+$/,:col_sep => " ") do |csv|
  p csv
end
# >> "Ram earns $2500 per month\n"
# >> "Arup earns $5000 per month\n"
# >> "Ayan earns $42,000 per mnth\n"
# >> "Anup earns $225000 per month\n" # should be skipped
# >> "Deba earns $450000 per month\n" # should be skipped

Here is the rubular link : http://rubular.com/r/P99VIRvBqS

Where did I do wrong ?

···

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

Code I tried :

require 'csv'

text = <<-STR
Ram earns $2500 per month
Arup earns $5000 per month
Ayan earns $42,000 per mnth
Anup earns $225000 per month
Deba earns $450000 per month
STR

File.write("test.csv",text)

File.foreach('test.csv',:skip_lines =>
/^[^0-9]+(\d{5,6})[^0-9]+$/,:col_sep => " ") do |csv|

I don't think File's (or IO's) foreach understands :skip_lines, does
it? I think you mean: CSV.foreach

···

On Sat, Feb 15, 2014 at 1:56 PM, Arup Rakshit <lists@ruby-forum.com> wrote:

  p csv
end
# >> "Ram earns $2500 per month\n"
# >> "Arup earns $5000 per month\n"
# >> "Ayan earns $42,000 per mnth\n"
# >> "Anup earns $225000 per month\n" # should be skipped
# >> "Deba earns $450000 per month\n" # should be skipped

Here is the rubular link : Rubular: ^[^0-9]+(\d{5,6})[^0-9]+$

Where did I do wrong ?

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

tamouse m. wrote in post #1136800:

I don't think File's (or IO's) foreach understands :skip_lines, does
it? I think you mean: CSV.foreach

You are right. I don't know, why I couldn't see that mistake by mean. It
is now working.

require 'csv'

text = <<-STR
Ram earns $2500 per month
Arup earns $5000 per month
Ayan earns $42,000 per mnth
Anup earns $225000 per month
Deba earns $450000 per month
STR

File.write("test.csv",text)

CSV.foreach('test.csv',:skip_lines =>
/^[^0-9]+(\d{5,6})[^0-9]+$/,:col_sep => " ") do |csv|
  p csv
end
# >> ["Ram", "earns", "$2500", "per", "month"]
# >> ["Arup", "earns", "$5000", "per", "month"]
# >> ["Ayan", "earns", "$42,000", "per", "mnth"]

···

On Sat, Feb 15, 2014 at 1:56 PM, Arup Rakshit <lists@ruby-forum.com> > wrote:

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