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 | |
by Anonymous Monk on Mar 29, 2010 at 03:56 UTC |