- 论坛徽章:
- 0
|
回复 25# glauke
没问题的, 你要的不就是个验证么。 以每次处理5M 为例.
- my $batch = 5 * 1024 * 1024;
- my $start = 1;
- my $end = $start + $batch;
- my @charsToBeChecked = ();
- open my $code, "<b";
- while (<>) {
- push @charsToBeChecked, split //, $_;
- if ( @charsToBeChecked > $batch ) {
- while (<$code>) {
- chomp;
- m/(\d+)\s*(\w)/;
- my $pos = $1 - $start;
- my $char = $2;
- next unless ( $pos < $batch and $pos >= 0 );
- if ( $charsToBeChecked[$pos] ne $char ) {
- printf STDERR "pos: %d, expected: %s actual: %s\n", $pos,
- $char, $charsToBeChecked[$pos];
- }
- }
- $start = $end + 1;
- $end = $start + $end;
- @charsToBeChecked = ();
- }
- }
- while (<$code>) {
- chomp;
- m/(\d+)\s*(\w)/;
- my $pos = $1 - $start;
- my $char = $2;
- next unless ( $pos < $batch and $pos >= 0 );
- if ( $charsToBeChecked[$pos] ne $char ) {
- printf STDERR "pos: %d, expected: %s actual: %s\n", $pos, $char,
- $charsToBeChecked[$pos];
- }
- }
复制代码 还可以先对校验文件做下预处理, 把它分成许多小文件 这样可以避免反复读去校验文件 |
|