in reply to This is why Perl is so frustrating

When you open a directory and read it, you get all the files in it. As you see "." and ".." are files in every directory. A directory is a file, so it could be that there are other sub-directories in your test directory.

opendir(DIRHANDLE, $testdir) or die "couldn't open directory: $testdir +"; @filenames = grep {-f "$testdir/$_"} readdir(DIRHANDLE); closedir(DIRHANDLE);
What the grep addition does is filter the ouput of readdir so that @filenames only winds up with filenames that are "normal files", ie, not directories. Meaning that "." and ".." and any other sub-dirs are excluded from the list! ergo, no need for the logic test on ne "." and ".."! Of course you already see that the filenames are just the raw names and the dir path needs to be prepended when you use those names, even in this grep.

Perl grep is way cool and is often used to filter lists. If the last statement in the grep evaluates to "true" the input on right is passed to output on left.

another point: no need to use . concatenation op in many string cases. Perl will interpolate a $var inside of double quotes (like die statement above) and -f "$testdir/$_", the quotes are needed otherwise Perl would think that this is a division.