Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

cwest (1514)

  (email not shown publicly)
AOL IM: caseyrwest (Add Buddy, Send Message)

Perl geek.

Journal of cwest (1514)

Monday January 26, 2004
05:25 PM


[ #17023 ]

The tree utility hasn't been ported to Mac OS X, and I found it easier to create a close approximation. I find it useful.

use File::Spec::Functions qw[splitpath];
($|, $\) = (1, "\n");
sub crawl {
  my ($dir, $line_prefix) = @_;
  my @entries = glob "$dir/*";
  foreach my $entry_num ( 0 .. $#entries ) {
    my $entry = $entries[$entry_num];
    my $last = $entry_num == $#entries;
    my $prefix = $last?'`':'|';
    print "$line_prefix$prefix-- ".
      (splitpath $entry)[2];
      $line_prefix.($last?' ':'|').' 'x3) if -d $entry;
print my $start = shift || '.';
crawl($start,'') if -d $start;

Posted from, comment here.

New comment creation has been disabled on this discussion.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login
Loading... please wait.