#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    5
    Rep Power
    0

    How to skip a line when reading a file


    Hi guys,

    How do I tell a program reading a file line by line to skip a line. For example I need to find a line which contains a match to a certain pattern and then I need to pull the name which appears on the next line in the file (but is not in a predetermined format so can't look for it directly). I imagine it should be something like this:

    page.each {|line|
    url = line.match(companyPattern)
    if url != nil
    line = line.next ???? how do i tell it to go to next line here??
    name = line.strip
    end
    }
    Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    Use next. An example:
    Code:
    irb(main):001:0> (1..10).each { |i| 
       next if i == 3 
       puts i 
    }
    1
    2
    4
    5
    6
    7
    8
    9
    10
    => 1..10
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog

IMN logo majestic logo threadwatch logo seochat tools logo