Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a listing of only plain files in a directory using Perl?

Tags:

perl

I'm looking for a way in Perl to list the plain files of a directory. Files only, no directories.

like image 731
Mike Avatar asked Nov 29 '22 19:11

Mike


1 Answers

You need to use opendir, readdir and closedir functions in conjunction with -f file test operator:

opendir(my $dh, $some_dir) || die $!;
while(my $f = readdir $dh) {
    next unless (-f "$some_dir/$f");
    print "$some_dir/$f\n";
}
closedir $dh;
like image 185
el.pescado - нет войне Avatar answered May 23 '23 15:05

el.pescado - нет войне