I have a file containing ~100 lines of text, each perhaps 100-200
characters in length.  I need to retrieve line $n from the file, where:
    $n = $julianday % $nlines;

$julianday = today's date (from localtime[7])
$nlines = no. of lines in the file

Method A
0. fopen() the file
1. read the file line by line with fgets() and count the lines ($nlines)
2. compute the required entry: $n=$julianday % $nline
3. rewind() the file and read it again until entry $n is found
4. fclose() the file

Method B
1. read the entire file into memory: $lines=file("myfile")
2. compute the required entry: $n=$julianday % count($lines)

I appreciate that this depends on the no. of lines in the file and
the size of the file. What I'm looking for is opinions on whether
the use of file() is more efficient than fgets(). It needs more memory,
but it eliminates reading the file twice.

Thanks.

--
John A. Grant  * I speak only for myself *  (remove 'z' to reply)
Radiation Geophysics, Geological Survey of Canada, Ottawa
If you followup, please do NOT e-mail me a copy: I will read it here




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to