in reply to testing files for valid content

my @files=grep {$_ ne '.' && $_ ne '..'} @files=readdir(DIR);

Not directly related to your question, but I've seen this construct a couple of times now in code you posted, so I thought it's maybe worth commenting on... before it becomes a habit :)

The 'normal' way to write this would be

my @files=grep {$_ ne '.' && $_ ne '..'} readdir(DIR);

No need to assign the list of files to an intermediate array — which is also a different (i.e. package) variable from the first lexical my @files, BTW.

Has anyone ever suggested to try use strict?  ;)

Replies are listed 'Best First'.
Re^2: testing files for valid content
by toolic (Bishop) on Apr 23, 2009 at 20:30 UTC
    Good advice.

    And if files are all that are needed (no directories), why not filter out all directories, not just those 2 special ones?

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

    where $dir is the directory path which DIR points to.