in reply to Directory Listing

Just to mention, this also lists the directories:
for (<*.*>) { print $_ if -d; }
It's better to use readdir() as mentioned above since it does not depend on the actual name (DOS has something with *.* and unix will not match directories without a dot). The advantage of this version is simplicity (and perlicity :)

Replies are listed 'Best First'.
RE: Re: Directory Listing
by turnstep (Parson) on Aug 10, 2000 at 01:47 UTC

    Actually, you don't want "start dot star" but simply "star". The latter will return only directories with a dot in it (in both Unix and DOS versions of perl)

    Even more perl-like:

    for (grep {-d} <*>) { ## Do stuff with $_; }

      FWIW I avoid idioms like the above ever since I got bitten by the fact that globbing is a shell operation. Very few will notice, but I have been in the position of needing to do an emergency rewrite when I passed the maxium number of files in a directory that could be listed. (What that limit is depends on the shell Perl was built with. That time it was a bit over 3000.) While readdir() is much more verbose, with it I have no fears about being bitten again.

      YMMV, warranty void where prohibited, etc.

      UPDATE
      jlp makes an excellent point below. I did not remember it, but once he said it I had a small bell go off. I had heard about that. Once 5.6.1 comes out I look forward to exploring what other goodness can be found therein.

        "...I got bitten by the fact that globbing is a shell operation"

        This is true only in versions of perl prior to 5.6. In 5.6, globbing is implemented internally using File::Glob. My benchmarking shows glob() in 5.6 to be two orders of magnitude faster than in prior versions. Not only that, but it is also faster than the opendir(), readdir(), grep idiom. (yes, I am aware of your objections to 5.6, but I have yet to encounter any bugs, personally)