Perl使用chdir的实例代码
程序员文章站
2022-04-29 20:09:30
复制代码 代码如下:use strict;use warnings;
# print all files in a directorysub print_files {&...
复制代码 代码如下:
use strict;
use warnings;
# print all files in a directory
sub print_files {
my $dir = 'd:/code';
opendir dir, $dir or die $!;
my @files = readdir dir;
chdir $dir; # use chdir or -f will not work, since -f need absolutely path
foreach my $file (@files) {
if (-f $file) {
print "$file\n";
}
}
closedir dir;
}
&print_files();