我正在尝试从文本文件中删除一行。相反,我已经清除了整个文件。有人可以指出错误吗?
removeReservation("john");
sub removeTime() {
my $name = shift;
open( FILE, "<times.txt" );
@LINES = <FILE>;
close(FILE);
open( FILE, ">times.txt" );
foreach $LINE (@LINES) {
print NEWLIST $LINE unless ( $LINE =~ m/$name/ );
}
close(FILE);
print("Reservation successfully removed.<br/>");
}
示例 times.txt 文件:
04/15/2012&08:00:00&bob
04/15/2012&08:00:00&john