Welcome to the Monastery | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Oh Holy Monks, I seek thy wisdom. Below is my code and output. My attempt is to create a hash of my directory listing. The parse_tree sub does exactly that, but I'm not happy with the results. I found this function from -- er, I believe here -- though it could have been SO. Regardless, my issue is with the way it's handling the root path. I do see a difference when I exclude the trailing '/' on my path, however an issue still remains. My issue is with the '' => 'home' => 'user' => 'bin' structure. If I exclude the trailing '/', the files under there are in the root of the hash, but then all folders fall under '' => 'TEST', etc. My additional issue is that I have not been able to figure out what the parse_tree function is actually doing. I'm just not skilled enough to understand these lines: nor how the hash %root is being populated. my goal is to have the data appear like this with Dumper: $VAR1 = { 'file1' => 'file01', 'file2' => 'file02' TEST => { 'file1' => 'file01' } test => { 'file3' => 'file03', subfolder => { 'file1' => 'file01' } 'file2' => 'file02', 'file1' => 'file01' } } }I'd like it this way because I won't necessarily know the directory that's being queried, and while I could certainly find more code and make it look like that, I'd prefer to understand what this is doing, and get ideas on what I need to do to get the format the way I'd like to see it from dumper. This will help me learn, and will also allow me to put comments on the code that i understand for when I look at this later on. Thank you for your time, @ output -- $ENV{"HOME"} . "/bin/"; directory hash dump $VAR1 = { '' => { 'home' => { 'user' => { 'bin' => { 'file2' => 'results.txt', 'file5' => 'rsync_logs', 'file1' => 'sdu.sh', 'file3' => 'parse_tree_test.pl', } } } }, 'TEST' => { 'file1' => 'file05', 'file2' => 'file03', 'file4' => 'file04', 'file3' => 'file02', 'file5' => 'file01' }, 'test' => { 'file1' => 'file02', 'file2' => 'file01', 'subtest' => { 'file2' => 'file06', 'file1' => 'file05' } } };output -- $ENV{"HOME"} . "/bin"; directory hash dump $VAR1 = { '' => { 'TEST' => { 'file1' => 'file05', 'file2' => 'file03', 'file4' => 'file04', 'file3' => 'file02', 'file5' => 'file01' }, 'test' => { 'file1' => 'file02', 'file2' => 'file01', 'subtest' => { 'file2' => 'file06', 'file1' => 'file05' } 'file2' => 'results.txt', 'file5' => 'rsync_logs', 'file1' => 'sdu.sh', 'file3' => 'parse_tree_test.pl', };
|
|