Thomas Luedeke wrote:
> inputFile = File.open( "filename","r" )
> inputArray = inputFile.readlines
> counts = 1
> xcob3cArray.each catch(:breakout) do |line|
>       line_number = counts
>       throw(:breakout) "$counts" if ( line.lstrip =~ /^(11))/ )
>       counts = counts + 1
> end
> line_number = $counts
> 
> ============================
> 
> Any help would be greatly appreciated!!

Definitely, evaluating the file a line at a time will be more efficient, 
but it's also worth noting that there is an error in your thinking about 
the 'each' block.

First, Ruby blocks don't work like Java iterators. That is, you can't 
use 'catch' and 'throw' the way that you have. Second, it is good 
programing practice to reserve 'throw's and 'catch'es for 
honest-to-goodness errors (this isn't just Ruby specific either).

In your case, you'd want to use 'break' ('next' is also good for loops). 
So, combining Robert's advice with mine (and another tip or two for 
conciseness and efficiency ;-) ), you'd have:

line_number = 0
File.open(inputFile) do |file|
  file.each_line do |line|
    line_number += 1
    break if line =~ /^\s*(11)/
  end
end

Cheers, and happy coding!

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