The Wayback Machine - https://web.archive.org/web/20160117174647/http://perldoc.perl.org/functions/readdir.html

Perl version

Modules

  • ABCDE
  • FGHIL
  • MNOPS
  • TUX

readdir

Perl 5 version 22.0 documentation

Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled, or are running a non-JavaScript capable web browser.

To get the best experience, please enable JavaScript or download a modern web browser such as Internet Explorer 8, Firefox, Safari, or Google Chrome.

Recently read

readdir

  • readdir DIRHANDLE

    Returns the next directory entry for a directory opened by opendir. If used in list context, returns all the rest of the entries in the directory. If there are no more entries, returns the undefined value in scalar context and the empty list in list context.

    If you're planning to filetest the return values out of a readdir, you'd better prepend the directory in question. Otherwise, because we didn't chdir there, it would have been testing the wrong file.

    1. opendir(my $dh, $some_dir) || die "can't opendir $some_dir: $!";
    2. @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
    3. closedir $dh;

    As of Perl 5.12 you can use a bare readdir in a while loop, which will set $_ on every iteration.

    1. opendir(my $dh, $some_dir) || die;
    2. while(readdir $dh) {
    3. print "$some_dir/$_\n";
    4. }
    5. closedir $dh;

    To avoid confusing would-be users of your code who are running earlier versions of Perl with mysterious failures, put this sort of thing at the top of your file to signal that your code will work only on Perls of a recent vintage:

    1. use 5.012; # so readdir assigns to $_ in a lone while test
 
Morty Proxy This is a proxified and sanitized view of the page, visit original site.