I'm attempting to read in a file via ARGF and perform some operations on it. Before doing anything else I need to read in a specific line and validate its contents.
I'm calling my script like so:
./main.rb < input.txt
I'm attempting to access the specific line (lets say line 10) like so:
if __FILE__ == $0
ARGF.lineno= 10
puts "lineno: #{ARGF.lineno}" # Prints 10 (as expected)
puts "readline: #{ARGF.readline}" # Prints contents of line 0 instead of 10!
end
I am able to manually set ARGF.lineno= per the docs, and this seems to work. However when I then attempt to read the line I just set, I get the contents of line 0. What, if anything, am I doing wrong?
Note that looping through the lines in order to get to the given line is not an option, my input data may be hundreds of thousands of lines long.
Thanks in advance for any help.