Charles K. Clarkson wrote: > Rob Dixon <[EMAIL PROTECTED]> wrote: > > > sub nfiles { > > opendir my $dh, $_[0] or die $!; > > my @dir = readdir $dh; > > return scalar @dir; > > } > > That should be decremented by 2 to account for '.' > and '..'. It could also get the count using '()': > > sub is_empty_dir { > return undef unless -d $_[0]; > opendir my $dh, $_[0] or die $!; > my $count = () = readdir $dh; > return $count - 2; > }
Well yes, but you're assuming he's working on a Unix system, and you ought to exclude all hidden files if you're going to do that. Certainly you shouldn't just knock off two without checking what you're ignoring. My submission was just a way of counting the files in a directory, to be modified as required. My 'enhanced' effort would be: sub nfiles { opendir my $dh, $_[0] or die $!; return grep /^[^.]/, readdir $dh; } But even then this includes all directories, links and so on, which may or may not be significant. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]