tell

Deleting a line from a huge file in Perl

扶醉桌前 提交于 2019-11-27 04:01:15
问题 I have huge text file and first five lines of it reads as below : This is fist line This is second line This is third line This is fourth line This is fifth line Now, I want to write something at a random position of the third line of that file which will replace the characters in that line by the new string I am writing. I am able to achieve that with the below code : use strict; use warnings; my @pos = (0); open my $fh, "+<", "text.txt"; while(<$fh) { push @pos, tell($fh); } seek $fh , $pos