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 );
We're building the house of the future together.

Replies are listed 'Best First'.
Re^2: Screwed tree scanning
by Maze (Sexton) on Sep 30, 2006 at 16:44 UTC

    yes something like that

    I think my posted code is a prima donna example of what can happen if you throw yourself into a task without first checking to see if it's already been done

    also your code shows me just how much I have yet to learn about perl, it uses syntatic magic I never knew was possible