in reply to Re^3: Searching text files
in thread Searching text files
I can't see much justification for anything more complicated.
Optionally searching for strings instead of numbers?
Not having to have a fixed record size or not having to know what the recordsize is? (note: there is a set recordsize function in File::SortedSeek which claims to improve performance, but I could not see any difference in speed from using it)
Anyway, here's your function using F:SS instead:
use File::SortedSeek; sub record_search { my ($key, $filename, $recordsize) = @_; my $fh = IO::File->new($filename, 'r') or croak("Could not open $filename: $!"); # I don't see any difference in speed with the next line # File::SortedSeek::set_line_length($recordsize); numeric( $fh, $key); return File::SortedSeek::was_exact(); }
Update: Looking at the answers below, I learned about Search::Dict, which would work just about as well, and has been in core perl since at least 5.6.1, but still supports my point about saving just a few lines.
|
|---|