Skip to Main Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced content levelIntermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

File::Find

use File::Find;

# Print out all directories below current one.
find sub { print "$File::Find::name\n" if -d }, ".";

# Compute total space used by all files in listed directories.
@dirs = @ARGV ? @ARGV : ('.');
my $sum = 0;
find sub { $sum += -s }, @dirs;
print "@dirs contained $sum bytes\n";

# Alter default behavior to go through symlinks
# and visit subdirectories first.
find { wanted => \&myfunc, follow => 1, bydepth => 1 }, ".";

The File::Find module's find function recursively descends directories. Its first argument should be a reference to a function, and all following arguments should be directories. The function is called on each filename from the listed directories. Within that function, the $_ variable is set to the basename of the current filename visited, and the process's current working directory is by default set to that directory. The package variable $File::Find::name is the full pathname of the visited filename. An alternative calling convention takes as its first argument a reference to a hash containing option specifications, including "wanted", "bydepth", "follow", "follow_fast", "follow_skip", "no_chdir", "untaint", "untaint_pattern", and "untaint_skip", as fully explained in the online documentation. This module is also used by the standard find2perl (1) translator program that comes with Perl.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl, 2nd Edition

Mastering Perl, 2nd Edition

brian d foy
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes
Perl in a Nutshell, 2nd Edition

Perl in a Nutshell, 2nd Edition

Nathan Patwardhan, Ellen Siever, Stephen Spainhour

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata