网络编程
位置:首页>> 网络编程>> 网络编程>> Perl使用chdir的实例代码

Perl使用chdir的实例代码

  发布时间:2023-02-13 19:33:56 

标签:Perl,chdir


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();

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com