This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Konlab's profile picture

Reading the 8th line

Started by Konlab, 01 February 2015 - 07:00 PM
Konlab #1
Posted 01 February 2015 - 08:00 PM
I have a config file and I need only the the 8th line. Is there an easier/shorter way to do it than this? :
<code>
local a = fs.open("example","r")
for i=1,7 do a.readLine() end
print(a.readLine())
a.close()
</code>
KingofGamesYami #2
Posted 01 February 2015 - 08:04 PM
No, not really.

(FYI, you used html tags instead of BBC tags)
Doyle3694 #3
Posted 02 February 2015 - 12:07 AM
I would however suggest that you read the whole file into a table. Doesn't have any technical advantage, but for making the code easier to understand and modify it is king. It also doesn't give cancer to people like me with heavy self-diagnosed OCD.
valithor #4
Posted 02 February 2015 - 01:16 AM
I would however suggest that you read the whole file into a table. Doesn't have any technical advantage, but for making the code easier to understand and modify it is king. It also doesn't give cancer to people like me with heavy self-diagnosed OCD.

Really if all he wants is the 8th line it would be better to not read the whole file into a table. It would be less efficent, and although you might not see it is slower. As you said there is no reason to do it so you shouldn't do it for no reason.
Konlab #5
Posted 02 February 2015 - 09:12 AM
No, not really.

(FYI, you used html tags instead of BBC tags)
ok thx
note: really oh :D/> I wasn't on these forums a half year ago :)/>