in reply to Determine if item is last one

when used in scalar context, readdir returns undef when there are no more entries:

opendir DIR, q{.} or die $!,$/; my $last; while (my $file = readdir DIR) { $last = $file; } print $last; ## this prints the last file closedir DIR;
yet, keep in mind that there is no order garanteed, so don't count on that.

OTOH, if you use readdir in list context, it will return you a null list when no entries are available.

opendir DIR, q{.} or die $!,$/; my @files = readdir DIR; closedir DIR; print $files[-1]; ## this prints the last file
Here you have control on the file ordering in the usual list sorting manner:
## sorted by name, case sensitive my @files = sort {$a cmp $b} readdir DIR;

--
AltBlue.