Subject: | Bug when many lines have the same data value, 1st is not found. |
Hello and thanks for File::SortedSeek.
Given a file with 100 lines, 10 of each of the numbers 0 to 9.
Calling numeric or alphabetic leaves the file position pointer
*not* at the beginning of the first matching line.
If you've log files with time granuality in seconds, and more
than 10 lines per second you might run into this.
There is a test below that demonstrates this.
I'd suggest using Search::Dict to do the binary search as it does
not suffer from this problem, this is also suggested in:
http://rt.cpan.org/Ticket/Display.html?id=23874
Note that bug:
http://rt.cpan.org/Ticket/Display.html?id=30778
suggests allowing a stationary override, this might help with
the behaviour I'm reporting if a suitable stationary override
is provided, but it doesn't seem like a comprehensive solution.
Cheers,
Peter (Stig) Edwards
use strict;
use warnings;
use Test::More tests=>2;
use File::SortedSeek;
# silence warnings to std err to avoid duplicates
File::SortedSeek::set_silent;
$|++;
my $file = './test.file';
open TESTOUT, '>',$file or die "Can't write test file $!\n";
# write 10 of each of the numbers from 0 to 9
foreach my $item (0..9) {
for ( 0..9 ) {
print TESTOUT "$item\n";
}
}
close TESTOUT;
open TESTIN, '<',$file or die "Can't read from test file $!\n";
my $tell = File::SortedSeek::numeric( *TESTIN, '7' );
my $num_of_sevens=0;
while ( my $line = <TESTIN> ){
if($line =~ m/7/mxo){
$num_of_sevens++;
} else {
last;
}
}
is($num_of_sevens,10,'10 sevens');
close TESTIN;
#1 while ( unlink $file );
ok (! -e $file,'Test file unlinked ok');
1;