Perl使用chdir的实例代码
摘要:复制代码代码如下:usestrict;usewarnings;#Printallfilesinadirectorysubprint_file...
复制代码 代码如下:
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 "$filen";
}
}
closedir DIR;
}
&print_files();
【Perl使用chdir的实例代码】相关文章:
★ Perl中使用File::Lockfile确保脚本单实例运行
上一篇:
perl中heredoc使用说明
下一篇:
perl特殊符号及默认的内部变量