您现在的位置是:网站首页> 编程资料编程资料
Perl使用chdir的实例代码_perl_
2023-05-26
291人已围观
简介 Perl使用chdir的实例代码_perl_
复制代码 代码如下:
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();
