in reply to Re: cant open files from a directory
in thread cant open files from a directory

my @files = grep { -f } map { "$dir/$_" } readdir($dirhandle);

To combat the excessive grepping & mapping going on above ...

my @files = map { -f $_ ?"$dir/$_" : () } readdir( $dirhandle ) ;

Replies are listed 'Best First'.
Re^3: cant open files from a directory
by kcott (Archbishop) on Feb 01, 2014 at 05:53 UTC

    I'd hardly consider one grep and one map to be "excessive grepping & mapping" nor something that one would need to "combat".

    However, should you prefer the style you've posted, "-f $_" suffers from the problem already pointed out four times in this thread.

    You could employ excessive usage of "$dir/$_", though. :-)

    -- Ken

      Blocks of grep & map were simple enough, which could have been combined simply, notwithstanding my lack of attention to ...

      Thanks for pointing out the bug the fifth time that I had missed in my zeal to curb the extravagance.

      I would rather have then map { $f = "$dir/$_" ; -f $f ? ... } ..., though some may find "$f" to be excessive. (By this time I would have busted out File::Find already to be honest.)