in reply to reading files and directories

next if $file =~ /^\.\.?$/;

When dealing with readdir, a better habit to get into for dealing with the . (current) and .. (parent) entries is to name them explicitly:

next if $file eq '.' or $file eq '..';

There's only two of them, no need to haul in regexp machinery just for that. If you want to be really platform agnostic, you could use File::Spec and

use File::Spec qw/curdir updir/; next if $file eq curdir() or $file eq updir();

Addendum: see this note which summarises the issue.

Replies are listed 'Best First'.
Re: Re: reading files and directories
by ysth (Canon) on Jan 07, 2004 at 19:21 UTC
    Remember that File::Spec is OO (only class methods, but OO nonetheless).

    You need either:

    use File::Spec; next if $file eq File::Spec::->curdir() or $file eq File::Spec::->updi +r();
    or to use the non-OO File::Spec::Functions:
    use File::Spec::Functions qw/curdir updir/; next if $file eq curdir() or $file eq updir();