use strict;
# let's assume you read the list from stdin:
my @paths = <>;
chomp @paths;
s/:$// for @paths; # don't want the punctuation
my $prev_path = shift @paths;
my $prev_depth = ( $prev_path =~ tr{/}{/} ); # count /'s
my $indent = 1;
print "
\n - $prev_path:
\n";
for ( @paths )
{
my $depth_now = ( tr{/}{/} );
if ( index( $_, "$prev_path/" ) == 0 )
{ # $prev_path is contained within this one, so indent
print ' ' x $indent, "\n";
$indent++;
}
elsif ( $depth_now < $prev_depth )
{ # need to back off the indentation
while ( $depth_now < $prev_depth ) {
$indent--;
print ' ' x $indent, "
\n";
$prev_depth--;
}
}
print ' ' x $indent, "- $_:
\n"; # put ":" back in
$prev_path = $_;
$prev_depth = $depth_now;
}
while ( $indent ) {
$indent--;
print ' ' x $indent, "
\n";
}
__OUTPUT__
- examples/html:
- examples/html/bars:
- examples/html/headers:
- examples/html/links:
- examples/html/lists:
- examples/html/menus:
- examples/html/rgb:
- examples/html/tables:
- examples/ps:
- examples/splash:
- examples/splash/dropbox:
- examples/splash/frame:
- examples/splash/hair:
- examples/splash/icon:
- examples/splash/menu:
- examples/splash/menubar: