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

grep can take a BLOCK with multiple tests and/or you can just use and and chain multiple checks (recommended best practice is to use the BLOCK form rather than the EXPR form these days anyhoo). Or use something like File::Find::Rule rather than lower level primitives.

my @F = grep { /^\w/ and not -d "$myDir/$_" } readdir( I );

Edit: Path::Tiny is another possibility.

use Path::Tiny; my @files = grep !$_->is_dir, path( $myDir )->children( qr/^\w/ );

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: How can I readdir and ! -d in one line
by misterperl (Friar) on Oct 27, 2020 at 17:22 UTC
    Ahh well crafted my friend, another ++ vote.. It occurs to be in linux I might PIPE the result to ! -d or something , but I don't know about any Perl pipe.

    TYVM

      A perl equivalent (of sorts) might be to chain greps on different conditionals, but (IMHO) that's not particularly clearer in this case than simply having the one predicate step check both conditions (not-dir and starts with a wordchar) at the same time.

      my @files = grep { ! -d qq{$myDir/$_} } grep { /^\w/ } readdir( I );

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.