You are basically interested in those directories in your tree which have no subdirectories; so the following algorithm should work:
- Initially create an empty hash %leaf_directories
- Whenever File::Find drops you into a directory $d, do the following:
- Remove the parent directory of $d from the hash, i.e. if $d contains the full path, do a delete $leaf_directories{dirname($d)}. Of course this will fail occasionally (because there is no corresponding entry), but we ignore this.
- Add $d to your hash, i.e. $leaf_directories{$d}=1
In the end,
keys $leaf_directories should be the list of the directories without subdirectories.
--
Ronald Fischer <ynnor@mm.st>