|laziness, impatience, and hubris|
How to map a directory tree to a perl hash treeby Rudif (Hermit)
|on Mar 10, 2001 at 19:03 UTC||Need Help??|
Rudif has asked for the
wisdom of the Perl Monks concerning the following question:
Everyone knows how to walk a directory tree and collect the file paths into a flat list, perhaps filtering them along the way.
However, I want to collect those paths into a tree of hashes, where keys would be file or subdirectory names and values would be a scalar for a file and a hashref for a subdirectory.
Once in a tree, I could apply recursive programs to do whatever I need with my files.
Here is my first try, with sample output (and a directory browser in 3 lines of perl :-).
What other/better ways to perform this dir-to-hash mapping would you suggest?