« Recursivly print directories in Perl...with no modules | Main | A filesystem recurser in Python too »

A shorter filesystem recurser in Perl

Shortened it up a bit...

#!/usr/bin/perl use strict; use warnings;

printdir( $ARGV[0] );

sub printdir
{
     my $dir          = $_[0] ? $_[0] : '.';
     my $handle      = ();
     
     print "Directory: $dir\n";
     
     opendir( $handle, $dir );
     my @items = sort( readdir( $handle ) );
     closedir( $handle );
     
     map
     {
          -d "$dir/$_"
          ? printdir( "$dir/$_" )
          : print "$dir/$_\n"
     } @items[2 .. $#items];
}

And people call Perl just a bunch of line noise?! Bah, sissies! :-P

TrackBack

TrackBack URL for this entry:
http://www.aviditysoftware.com/cgi-bin/mt/mt-tb.cgi/11

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on September 5, 2006 9:50 AM.

The previous post in this blog was Recursivly print directories in Perl...with no modules.

The next post in this blog is A filesystem recurser in Python too.

Many more can be found on the main index page or by looking through the archives.