Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there Monks!
How can I make my program here more efficient or dynamic to keep finding all directories on its path when the user clicks on the links. I got it to work down to one level but it could be several level deep into a directory path. It needs to be more dynamic. I am just stuck on this one.
If someone has a test directory with about 3 or more levels deep, just set it up and you will see what I am talking about it.
Here is the code
#!/perl/bin/perl use warnings; use strict; use File::Slurp::Tree; use CGI qw(:header); use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; my $dir = param("dirnewpath"); my $flag = param("flag"); my $one; my $sub_all_dir = param("deepin"); print header(); if(!$dir){ $dir = "c:/progra~1/apache~1/apache2/cgi-bin"; }else{ $dir= $dir; } opendir(DIR,$dir)|| die "Can't open $dir\n"; my @content=sort(readdir(DIR)); foreach (@content){ next if (/^[\.]/); my $all_dir =$_; chomp($all_dir); if(-d $dir."/".$all_dir){ print "<a href=\"temp.pl?dirnewpath=$dir&flag=true\"><img src= +../../tree/images/dir.gif border=0><b>$all_dir</b></a><br>"; if($flag){ opendir(SUBDIR,$dir."/".$all_dir)|| die "L26-Can't +open $dir\n"; my @subcontent=sort(readdir(SUBDIR)); foreach(@subcontent){ next if (/^[\.]/); $sub_all_dir = $_; if(-d $dir."/".$all_dir."/".$sub_all_di +r){ print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& +nbsp;<a href=\"temp.pl?dirnewpath=$dir/$all_dir&flag=true&\"><img src +=../../tree/images/dir.gif border=0> <b>$sub_all_dir</b></a><br>"; }else{ print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input +type=checkbox> L66 - $sub_all_dir<br>";} } closedir(SUBDIR) or die "Can't close SUBDIR +" } }else{ print "<input type=checkbox> $all_dir<br>"; } } closedir(DIR) or die "Can't close DIR";

Thanks for the help!!!

(Unreaped by tye since "similar" ne "duplicate")

edit (broquaint): Added <readmore> per consideration.

Replies are listed 'Best First'.
Re: Clickable Path to Files
by Joost (Canon) on Jul 11, 2006 at 20:19 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Clickable Path to Files
by CountZero (Bishop) on Jul 12, 2006 at 06:18 UTC
    Isn't that something which an Apache webserver knows how to do all by itself already? Have a look at: Autoindex and related options (off-site link).

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      At the end this script will not be running on Apache, unfortunately.