On Thu, 13 May 99 10:16:43 -0700, Chilton Webb wrote: >I've been knocking this one around in my miniature brain for about a >month now, so I guess I'm not going to figure it out on my own. > >I have a list of files, with this structure... Actually I think this question would belong better in the MacPerl-AnyPerl list. Anyway, this seems to work alright. BTW no regex in sight. And beware, because of the __DATA__ I cannot use the __END__ trick (those are equivalent). #! perl -w chomp(my @line = <DATA>); # convert Macintosh paths to anonymous arrays of disk, folder names and # basename. Sort. my @path = sort { for(my $i=0; $i<$#$a && $i<$#$b; $i++) { # disk and folder names my $compare = $a->[$i] cmp $b->[$i]; return $compare if $compare; } # all identical up till now return @$a <=> @$b # files before folders || $a->[-1] cmp $b->[-1]; # sort among files } map { [ split /:/ ] } @line; #Sorted. Now print the tree. { my @common; #memory foreach my $pathref (@path) { my $i = 0; while($i<@common) { last unless $pathref->[$i] eq $common[$i]; } continue { $i++; } while($i<@$pathref) { print " " x $i,$pathref->[$i],"\n"; } continue { $i++ } } continue { @common = @$pathref; # for next loop } } __DATA__ Macintosh HD:myFiles:a.txt Macintosh HD:myFiles:b.txt Macintosh HD:myFiles:more:aaa:a.txt Macintosh HD:myFiles:more:a.txt Macintosh HD:myFiles:more:b.txt Macintosh HD:myFiles:more:yetmore:a.txt Macintosh HD:myFiles:more:yetmore:b.txt Macintosh HD:yurFiles:a.txt Macintosh HD:yurFiles:b.txt ===== Want to unsubscribe from this list? ===== Send mail with body "unsubscribe" to macperl-request@macperl.org