[thelist] Perl Script question

Erik Sabowski Erik.Sabowski at noaa.gov
Wed Jul 12 13:03:26 CDT 2000


got access to a copy of the Perl Cookbook? if you are going to be using
perl, i'd suggest getting it, it has answers to many perl questions, i'm
surprised how many of the questions i have are answered in it.

use the File::Find module. it will process each file in a directory (and
it's subdirectories) with the subroutine you write for it, so in your
case, you will write the subroutine to print out the file names

so you can do something like this:


@ARGV = qw(.) unless @ARGV;   #if argv is empty, use . for the directory
(current directory)
use File::Find;

sub printfiles {
	print $_, -d && '/',"\n"; #print out names of files, and print a "/" at
the end of
                                  #directories
}

find(\&printfiles, @ARGV);


this will print out the list of files contained in the directory
specified in @ARGV, as well as print a '/' at the end of those which are
directories. but, will also list the files in those directories as well.
if you would like it to not descend into those directories, and just
print out the names in the directory specified, set $File::Find::prune
to true. also, if you want the full path to be printed out will the name
of the file, use $File::Find::name instead of $_.

i guess that about covers it. for more info, look up the File::Find
module, the documentation should go into more detail if you need it.

HTH

#airyk

-- 
+----------------------------------------------------+
| Erik M. Sabowski          Computer Assistant       |
| erik.sabowski at noaa.gov    National Geodetic Survey |
|   ----------------------------------------------   |
|    National Oceanic and Atmospheric Association    |
+----------------------------------------------------+




More information about the thelist mailing list