To do list for the following code, in any order. I have tried doing these, but my efforts have lead to bigger messes.

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Cwd; use File::Find; use File::Basename; my $filename = basename($0); my $dirname = getcwd; my %directories = ( '/ftp/pub/www/fantasy' => { link => 'http://www.xecu.net/fantasy', user => 'Fantasy', name => "Fantasy's Realm", }, '/home/lady_aleena/var/www' => { link => 'http://lady_aleena.perlmonk.org', user => 'Lady Aleena', name => "Lady Aleena's Home", }, 'C:/Documents and Settings/<my name>/My Documents/fantasy' => { link => 'file:///C:/Documents and Settings/<my name>/My Documents/ +fantasy', user => '<my name>', name => "<my name>'s Place", }, ); sub get_rootdir { for my $dir (keys %directories) { return $dir if $dirname =~ /^\Q$dir/; } } my $rootdir = get_rootdir; if (not exists $directories{$rootdir}) { die "You really screwed up." +} my $rootlink = $directories{$rootdir}{link}; my $rootuser = $directories{$rootdir}{user}; my $rootname = $directories{$rootdir}{name}; #@ARGV == 1 and -d $ARGV[0] or die "Usage: $0 path_name\n"; #( $rootdir = shift ) =~ s{(?<!/)$}{/}; # make sure path ends with " +/" my %tree; $tree{$rootdir} = {}; find(\&wanted, $rootdir); print_tree( \%tree, 0 ); sub wanted { local $_ = $File::Find::name; if ( -f ) { # only work on data files (skip directories) s{\Q$rootdir\E}{}; # remove the rootdir string from the path name load_tree( $tree{$rootdir}, fileparse( $_ )); } } # recursively load the hash structure # (first call gets top-level hashref, and file name, path from File::B +asename::fileparse) sub load_tree { my ( $href, $name, $path ) = @_; my @dirs = split /\//, $path; push @dirs, '.' if ( $dirs[$#dirs] ne '.' ); my $key = shift @dirs; while ( @dirs and $key ne '.' and exists( $$href{"$key/"} )) { $href = $$href{"$key/"}; $key = shift @dirs; } if ( $key ne '.' and ! exists( $$href{"$key/"} )) { $$href{"$key/"} = {}; load_tree( $$href{"$key/"}, $name, join( '/', @dirs, '' )); } elsif ( $key eq '.' ) { push @{$$href{"$key/"}}, $name; } } # recursively print embedded lists sub print_tree { my ( $href, $indent ) = @_; printf( "%s<ul>\n", ' ' x $indent ); $indent++; if ( exists( $$href{'./'} )) { printf( "%s<li>%s</li>\n", ' ' x $indent, $_ ) for ( @{$$href{'./'}} ); delete $$href{'./'}; } if ( keys %$href ) { for my $subdir ( sort keys %$href ) { printf( "%s<li>%s\n", ' ' x $indent, $subdir); $indent++; print_tree( $$href{$subdir}, $indent ); $indent--; printf( "%s</li>\n", ' ' x $indent ); } } $indent--; printf( "%s</ul>\n", ' ' x $indent ); }

sub transform

sub transform { my ($text) = @_; $text =~ tr/_/ /; $text =~ s/.*\/+//; $text =~ s/\.[^.]*\z//; return $text; }
Have a nice day!
Lady Aleena

In reply to Re^6: Directory Tree Structure by Lady_Aleena
in thread Directory Tree Structure by rupesh

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.