779 posts
Location
Kerbin
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>
3057 posts
Location
United States of America
Posted 01 February 2015 - 08:04 PM
No, not really.
(FYI, you used html tags instead of BBC tags)
818 posts
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.
1023 posts
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.
779 posts
Location
Kerbin
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 :)/>