Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How can I readdir and ! -d in one line

by haukex (Archbishop)
on Oct 28, 2020 at 21:17 UTC ( [id://11123281]=note: print w/replies, xml ) Need Help??


in reply to How can I readdir and ! -d in one line

Personally I prefer Path::Class:

use Path::Class qw/dir/; my @files = sort grep { !$_->is_dir && $_->basename=~/^[^.]/ } dir($path)->children;

Alternatively, a core-only way to do it is:

use File::Spec::Functions qw/ no_upwards catfile catdir /; opendir my $dh, $path or die "$path: $!"; my @files = sort map { catfile($path,$_) } grep { ! -d catdir($path,$_) && /^[^.]/ } no_upwards readdir $dh; closedir $dh;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123281]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-16 09:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found