in reply to Re^3: Directory Tree Help!
in thread Directory Tree Help!

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!