in reply to Screwed tree scanning
Ah - something like this:
use File::Find; use XML::Simple; use strict; use warnings; my $root = shift or die "Usage: $0 rootdir\n"; my %tree; find( sub { #print "$File::Find::name\n"; my @path = split m,/,, $File::Find::name; my $tree = \%tree; $tree = (($tree->{'dir'} ||= {})->{shift @path} ||= {}) while @path > ( -d _ ? 0 : 1 ); @path and # it's a file push @{ $tree->{'file'} ||= [] }, shift @path; }, $root ); print XMLout( \%tree );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Screwed tree scanning
by Maze (Sexton) on Sep 30, 2006 at 16:44 UTC |