>>>>> "CT" == Chris Thorpe <[EMAIL PROTECTED]> writes:
CT> You can't do it in O(1) memory and O(n) time. There's a time/memory CT> tradeoff. At line m, you have to store m/2 lines in memory if you use CT> O(n) time, if the file stops anywhere between m and m*2 (which you don't CT> know.) you can do it in O(1) memory and O(n) time. just take schwern's File::ReadBackwards solution with a fix to the module so it supports TELL. and compare the tell values to see when you have read the middle line. then you only read the entire file once (maybe with a dup read of the center line) which is O(n) in time. and it uses no more than 1 buffer (actually 2) of data which is O(1) in memory no matter the size of the file. that assumes normal size lines and not enormous ones. uri -- Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com -- Stem is an Open Source Network Development Toolkit and Application Suite - ----- Stem and Perl Development, Systems Architecture, Design and Coding ---- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
