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.


In reply to Clickable Path to Files by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.