http://qs321.pair.com?node_id=469343


in reply to No. files in folder

That's fine. But it will only work your pwd is $dir. Otherwise you will have either to move there or prepend it to the filenames. Personally I think that while opendir is great and necessary in some circumstances, it is quite often abused where a simple glob (which does an opendir, and a readdir, and all the dirty jobs for you behind the scenes) would suffice.

Update: incidentally -0 == 0. Probably the code originally had the sort the other way round and [-1,-2] as subscript.