sri1230 has asked for the wisdom of the Perl Monks concerning the following question:

Can someone tell me why it wont work. I am trying to get all the empty files or files that match a pattern and dont end in txt prn or csv my @SrcFiles = grep {-z or /($SrcPattern)(?<!txt|prn|csv)$/} readdir(DIR)

Replies are listed 'Best First'.
Re: filter empty files
by ikegami (Patriarch) on Sep 24, 2009 at 18:21 UTC

    readdir returns file names, not paths, so -z could be failing to find the (right) file to check.

    By the way, it would be faster to check -z second (since it requires an io call), and it would be better to avoid needless captures.

    opendir(my $dh, $dir) or die("opendir: $!\n"); my @files = grep { ( !/\.(?:txt|prn|csv)\z/ && /$SrcPattern/ ) || -z } map "$dir/$_", readdir($dh);
      thanks i forgot this part "readdir returns file names, not paths" Appreciate your help!