You need a readdir .
For instance:
#! /usr/bin/perl use warnings; use strict; my $dir = "/tmp/foo"; opendir my $dh, $dir or die "$0: opendir: $!"; while (defined(my $name = readdir $dh)) { next unless -f "$dir/$name"; print "$name\n"; }
Launch:
$ ls -F / tmp / foo
abcd /
$ ./prog.pl
b
c
a
As you can see, the names come out in the order in which they are physically stored in the file system, which is not necessarily sorted.
To go on a quick and dirty route, you can also use the glob operator, as in
print map { s!^.*/!!; "$_\n" } grep !-d $_ => </tmp/foo/*>;
Note that you will have to remove directories from the result, and the glob operator does not return files whose names begin with periods.
source share