in reply to Read from directory list...

Most of the time, I tend to prefer glob to opendir followed by readdir, but that's mostly stylistic.

For glob, you would do something vaguely like:

my @list = glob('*');

I believe glob ignores hidden files (on *ix, files with names starting with "."), while readdir doesn't. With readdir, you'll always get at least two files, as . (the directory itself) and .. (its parent) will (almost) always show up (offhand, I don't know if .. will show up for the root directory on *ix), so you'll have to handle these if you're going to recurse through a directory tree, a la find.

emc

Insisting on perfect safety is for people who don't have the balls to live in the real world.

—Mary Shafer, NASA Dryden Flight Research Center

Replies are listed 'Best First'.
Re^2: Read from directory list...
by klekker (Pilgrim) on Feb 06, 2007 at 20:35 UTC
    > I believe glob ignores hidden files (on *ix, files with names starting with "."),
    > while readdir doesn't.

    It depends on how you call glob:
    In a directory containing the files aaaa, bbbb, cccc, .dddd, .eeee, .ffff

    glob (and similar '<>'):
    $ perl -e "print '-> ', join '|', glob('*');" -> aaaa|bbbb|cccc $ perl -e "print '-> ', join '|', glob('.*');" -> .|..|.dddd|.eeee|.ffff $ perl -e "print '-> ', join '|', glob('* .*');" -> aaaa|bbbb|cccc|.|..|.dddd|.eeee|.ffff
    readdir:
    $ perl -e "opendir DIR, '.'; print '->', join '|', readdir(DIR);" ->.|..|aaaa|bbbb|cccc|.dddd|.eeee|.ffff

    klekker