in reply to Re: reading the file using the line number
in thread reading the file using the line number

actually this problem makes me think of a fairly recent discussion on p5p about the non-linear behaviour of the perl internal unicode implementation in the regex engine

the problem is that to know the line position or the character position (supposing characters don't have all the same size) you have to count from the start...OR...do a bit of preparation, you put "markers" along the way

maybe Tie::File uses something similar but essentially you keep the byte position of the start of every line = 0 modulo k, so to find line n *k +q seek to marker n and read q lines from there

markers can be created as you fetch the lines, o pre-created in one go -- in the case of the regex engine, the algorithm could go both ways depending on the size of the "text" to match, or the maximum backtrack so far

hth --stephan
  • Comment on Re^2: reading the file using the line number