in reply to Directory Tree Structure

Hi

This is one example of using recursion to solve it.

use strict; my $path = '/var/www/html'; print "<ul>\n"; recurse_path($path, " "); print "</ul>\n"; sub recurse_path { my $path = shift; my $padding = shift; my $dir = $path; $dir =~ s/.*\///g; print "$padding<li><a href=\"$path\">$dir</a>\n"; my $has_subdir = 0; foreach(glob("$path/*")) { if(-d $_ && ! $has_subdir) { print "$padding<ul>\n"; $has_subdir = 1; recurse_path($_, $padding . " ") } elsif(-d $_) { recurse_path($_, $padding . " ") } } if($has_subdir) { print "$padding</ul>\n" } }

Replies are listed 'Best First'.
Re^2: Directory Tree Structure
by Lady_Aleena (Priest) on Mar 21, 2010 at 23:10 UTC

    Hello mickep76,

    I know it's been a few months since you posted this, but I just saw it. FYI, you aren't closing the list items (</li>). I would give it a shot, but your recursion is confusing me a bit.

    Have a nice day!
    Lady Aleena