Next | Lightweight Databases | 95 |
Inside, Tie::File uses a combination of several of the techniques we've seen
It maintains an offset table internally
$z = $FILE[57];
This checks the offsets table for $offsets[57]
If it's already present, Tie::File seeks to the right location and reads the record
If not, Tie::File scans from the last known position up to line 57
sub _fetch { my ($self, $n) = @_; ...
if ($#{$self->{offsets}} < $n) { return if $self->{eof}; my $o = $self->_fill_offsets_to($n); # If it's still undefined, there is no such record, # so return 'undef' return unless defined $o; }
my $fh = $self->{FH}; # we can do this now that offsets is populated $self->_seek($n); my $rec = $self->_read_record; ...
$rec; }
Next | Copyright © 2003 M. J. Dominus |