【发布时间】:2012-02-13 18:04:10
【问题描述】:
我正在尝试编写一个 perl 脚本,它将 test.txt 文件中的文件名读取到一个数组中,然后根据数组中的文件名删除文件。这是我到目前为止所得到的......
#!/usr/bin/perl
use strict;
use warnings;
open(FILE, "test.txt") or die("Unable to open file.");
my @data = <FILE>;
close(FILE);
foreach my $line (@data){
unlink($line);
}
test.txt 和 remove_files.pl 与要删除的文件位于同一目录中。我不知道为什么脚本不会删除文件。我错过了一个模块吗?
【问题讨论】:
-
第一个提示是检查错误:
unlink($line) or warn "$0: could not unlink $line: $!\n"
标签: perl delete-file