Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Directory Tree Structure

by mickep76 (Beadle)
on Oct 05, 2009 at 09:19 UTC ( [id://799203]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://799203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2026-02-07 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.