| Next | Lightweight Databases | 17 | 
Moreover, byte-oriented operations are inconvenient for record-oriented programs
Counting the number of bytes is easy:
        my $n_bytes = -s $file;
Counting the number of lines is hard:
        open F, "<", $file;
        while (<F>) {
          $n_lines++;
        }
Reading or writing at a certain byte position is easy:
        seek F, $B_POSITION, SEEK_SET;
Reading or writing at a certain line position is hard:
        seek F, 0, SEEK_SET;  $REC = 1;
        <F> until $REC++ >= $L_POSITION;
The copy-the-file technique is simple, but it always pays the maximum possible cost
| Next |  | Copyright © 2003 M. J. Dominus |