org chen wrote:
I have a huge file, there are 47,286,116 lines. I am search a line and
repalce this line with another string. I know this line is between
20,000,000th to 30,000,000th lines. Which way is more fast and safe:
method 1:
use Tie::FILE;
tie my @array, 'Tie""File', "aa.txt", memory =>100_000_000 or die;
for(my $i = 20000000; $i < 30000000; $i ++){
.......
}
untie @array;
method 2;
open(AA, "aa.txt");
while(<AA>){
...
}
close(AA);

20,000,000 is about at the middle of the file so start there first:

use Fcntl ':seek';

open my $AA, '<', 'aa.txt' or die "Cannot open 'aa.txt' $!";
seek $AA, ( -s $AA ) / 2, SEEK_SET or die "Cannot seek 'aa.txt' $!";

while ( <$AA> ) {
...
}
close $AA;




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to