If you're using a version of File::Find that supports pre- and postprocess hooks (>= Perl 5.6, IIRC) then you can do something like...
#!perl -l
# TESTED WITH v5.6.1 (MSWin32-x86-multi-thread) ONLY!
require 5.006;
use strict;
use File::Find 'find';
my $INDENT_DELIM = ' ';
my $DEPTH = 0;
find(
{
wanted => \&wanted,
preprocess => \&pre,
postprocess => \&post,
},
@ARGV ? @ARGV : "."
);
sub pre {
print indent( '<li id="folder">' . $_ . '</li>' );
print indent( '<ul>' );
$DEPTH++;
@_;
}
sub post {
$DEPTH--;
print indent( '</ul>' );
}
sub wanted {
return if -d;
print indent( '<li>' . $_ . '</li>' );
}
sub indent {
return $INDENT_DELIM x $DEPTH . $_[0];
}