Here it "WORKS", just put your directory name in line 13 and this code will list all .pl or .pm files in that directory, and if you click on the file name it will show all modules used by that file. It needs improvements, any help its appreciated. Next step could be to find any database table used by these files and listed there as well.
Here is the code.

#!/usr/bin/perl -w use strict; use CGI qw(:header); use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; my $q = new CGI; my $show = param("show"); #my $input_dir = $ARGV[0] || '.' ; my $input_dir = "../my_directory"; my $arg_name = $q->param( 'arg_name' ) || ''; my $file_name = $q->param( 'fname' ) || ''; my @file_path; print header(); print "<html> <head><title>Directory Tree 4</title> </head> <body> Start<br> "; MAIN: { my @tree; dirwalk ($input_dir,\@tree); printtree(\@tree); } sub dirwalk { my ($dir,$tree) = @_ ; push @{$tree},($dir =~ m#([^/]+$)#); opendir DIR, $dir || die "Couldnt open $dir - $!\n"; my @entries = grep !/^\.{1,2}$/, readdir(DIR); closedir (DIR); foreach my $item (@entries) { my $fullpath = "$dir/$item"; push @file_path, $fullpath; #print "<br>59 - $fullpath<br>"; if ( -d $fullpath ) { dirwalk ( $fullpath,\@{$tree->[@{$tree}]}); } else { push @{$tree},$item; #print "<br>$item<br>"; } } } sub printtree { my $tree = shift; my $c=-1; print "<ul><li><a href=\"#\">&nbsp;",shift @{$tree},"</a><br>\n"; foreach my $item ( @{$tree} ) { $c++; if (ref $item eq "ARRAY" ) { printtree($item); #if any subdirectories are found, call will +be here } else { print "<ul><li><a href=\"dir_tree.pl?fname=$item\">\n"; print $item,"</a></li></ul>\n"; if($file_name eq "$item") { get_modules($input_dir,$file_name,\@file_path); } } } print "</li>"; print "</ul>"; } sub get_modules { my $dir = $_[0]; my $get_files = $_[1]; my @fullpath = @{$_[2]}; my @just_path; foreach my $just_path(@fullpath) { if($just_path=~/(.*?)(\/$get_files)(.*?)/g) { $just_path=~s/(.*?)(\/$get_files)(.*?)/$1/; $just_path=$1; push @just_path, $just_path; } } my $path = shift(@just_path); my (@all_files, @all_mod); opendir DIR, $path || die "Couldnt open $path - $!\n"; while (my $find_file = readdir(DIR)) { next unless (-f "$path/$find_file"); # Use a regular expression to find files ending in .pl next unless ($find_file =~ m/(\.pl|\.pm)$/); push @all_files, $find_file; } closedir(DIR); foreach my $f_modules(@all_files) { open (FILE, "$path/$f_modules"); while(my $file_line= <FILE> ){ if(grep /\buse\b/, $file_line) { if( ($f_modules eq "$file_name") && ($file_line!~/^#/g) ) { #$file_line=~s/\buse\b//g; print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp +;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$file_line<br>"; push @all_mod, $file_line; } } } close FILE; } } print "<br>End </body> </html> ";

Thanks for the help!

In reply to Re^4: Directory Tree Help! by Anonymous Monk
in thread Directory Tree Help! 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.