有什么理由为什么以下构造不起作用?文件列表包含文件名称。名称列表包含一个名称列表,这些名称在作为子字符串与文件名相匹配时,会导致循环将文件移动到名为$ name的目录。它似乎应该工作,但它不是在移动文件。什么是更好的方式来构建这个?将文件移动到目录
FILE: for my $file (@file_list) {
for my $name (@name_list) {
if ($file =~ /^\Q$name\E/) {
rename "/Users/path/to/file/I/need/to/move/$file", "/Users/path/to/directory/i/need/to/move/file/to/$name/$file" or die "rename failed because: $!\n";
next FILE;
}
}
print "no match for $file\n";
}
什么语言是您使用? – 2013-04-22 00:26:48
@ChrisLoonam看起来像PHP – alfasin 2013-04-22 00:27:45
这看起来更像Perl而不是PHP(''我的$ var'和'=〜'是符号之一)。 – michaelb958 2013-04-22 00:29:59