in reply to Directory Listing

Something no one else has seemed to notice yet on this line:
my @files = grep !/^\.\.?/ && /.*pm$/, readdir DIRH;
Why exclude the '.' and '..' directories, when you're only including '.pm' files anyway?

Update: There is also a Death to Dot Star! issue here, so in summation it should be:
my @files = grep /\.pm$/, readdir DIRH;

Replies are listed 'Best First'.
Re: Re: Directory Listing
by merlyn (Sage) on Jan 09, 2001 at 21:13 UTC
    my @files = grep !/^\.\.?/ && /.*pm$/, readdir DIRH;
    That not only exludes dot and dot-dot, but anything beginning with dot and dot-dot. Maybe it was intended to exclude ".random.pm", perhaps?

    But yes. On a code review, I'd mark that line as "either do what you mean, or write what you mean as a comment".

    -- Randal L. Schwartz, Perl hacker

      Update: Read these out of order, but was basically reinforcing the point that all we need is:

      my @files = grep /pm$/, readdir DIRH
        If you really want to match Perl modules, that should of course be: grep /\.pm$/, readdir DIRH; Otherwise, you're going to match rpm files, ppm files, and any other files ending in pm. :)
Re: Re: Directory Listing
by agoth (Chaplain) on Jan 09, 2001 at 21:59 UTC
    Just not backtracking and cleaning up my code very well,
    I initially thought just to exclude '.' and '..' but then thought I'd better be a bit more specific with *.pm, and seeing I know what the filename will start with the !/^\./ is pretty superfluous.