Determine the contents of a directory tree?
#find function side effect variables
#VARIABLE NAME CONTENTS
#$dir The current directory name
#$_ The current file name within that directory
#!/usr/local/bin/perl -w
use Getopt::Long;
use File::Find;
my $ret = GetOptions ("d|directory:s");
my $directory = $opt_d || die "Usage: $0 -d directory\n";
sub wanted
{
print "Dir =<$dir>\n";
print "Name=<$name>\n";
print "File=<$_>\n";
}
find(\&wanted, $directory);
Related examples in the same category