in reply to readdir and while - magic?
$ perl -MO=Deparse -e 'while($file = readdir(D)) { print $file; }' while (defined($file = readdir D)) { print $file; } -e syntax OK [download]
This is explained in more detail at A most obscure bug.
-- John.