Jump to content




Reading the 8th line


  • You cannot reply to this topic
4 replies to this topic

#1 Konlab

  • Members
  • 595 posts
  • LocationKerbin

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>


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 01 February 2015 - 08:04 PM

No, not really.

(FYI, you used html tags instead of BBC tags)

#3 Doyle3694

  • Members
  • 815 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.

#4 valithor

  • Members
  • 1,053 posts

Posted 02 February 2015 - 01:16 AM

View PostDoyle3694, on 02 February 2015 - 12:07 AM, said:

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.

#5 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 02 February 2015 - 09:12 AM

View PostKingofGamesYami, on 01 February 2015 - 08:04 PM, said:

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 :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users