How to delete the last 5 lines of a file
问题 I have several commands printing text to a file using perl. During these print commands I have an if statement which should delete the last 5 lines of the file I am currently writing to if the statement is true. The number of lines to delete will always be 5. if ($exists == 0) { print(OUTPUT ???) # this should remove the last 5 lines } 回答1: You can use Tie::File: use Tie::File; tie my @array, 'Tie::File', filename or die $!; if ($exists == 0) { $#array -= 5; } You can use the same array when