Perl 5 version 28.0 documentation
- 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.
As of Perl 5.12 you can use a bare readdir in a
whileloop, which will set $_ on every iteration. If either a
readdirexpression or an explicit assignment of a
readdirexpression to a scalar is used as a
forcondition, then the condition actually tests for definedness of the expression's value, not for its regular truth value.
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:
- use 5.012; # so readdir assigns to $_ in a lone while test