perl opendir使用问题,为什么老说找不到文件呢
use warnings;
use strict;
my $file='C:\Perl64\homework';
OpenFile('$file');
exit;
sub OpenFile{
my ($directory)=@_;
opendir(FOLDER,$directory) or die "cannot open $file($!)\n";
my @files=grep(!/^\.\.?$/, readdir(FOLDER));
closedir FOLDER;
foreach my $file(@files){
if(-f $directory/$file){
print "$directory/$file\n";
}
elsif(-d $directory/$file){
OpenFile('$directory/$file');
}
}
}
在windows下编的程序,路径完整给出,但每次运行都说No such file or directory, 哪里不对呢? perl opendir warnings
[解决办法]
if(-f $directory/$file)
这个斜线写反了if(-f $directory\$file)
如果不行,使用if(-f $directory.'\'.$file)