in reply to Re: popping or shifting a line off a file
in thread popping or shifting a line off a file
i'll add in flocking etc tonight.print &popline("passcodes.txt",10,7); sub popline { my ($file, $lineswanted, $linelength) = @_; open DATA, "+< $file"; my @fileinfo = stat DATA; my %records = (); $records{filesize} = $fileinfo[7]; $records{wanted_bytes} = $lineswanted * $linelength; $records{readpoint} = $records{filesize} - $records{wanted_byt +es}; # seek (DATA, -$records{wanted_bytes},2); # reads from the end + of file, readpoint computation not necessary seek (DATA, $records{readpoint},0); # reads from beginn +ing, used b/c readpoint computation needed for truncate my @lines = <DATA>; truncate(DATA,$records{readpoint}); return @lines; }
|
|---|