in reply to file globbing in a nested while loop
There's a module that does exactly what you're looking for, it's called File::Find. It allows you to traverse a file tree, and (should you so desire) perform operations based upon each file you come across.
Here's some code that demonstrates how to use File::Find to find and print the location of .pl files.
If you don't like to specify the sub-routine seperately, you can do it with an anonymous subroutine.use File::Find; find(\&printer, "/path/to/dir"); sub printer { print "I have found $File::Find::name\n" if /\.pl$/; }
Please note that newer versions of File::Find contain some very rich features, much more than the manual page here on PerlMonks. Check your local install to see what extra fun you can find.use File::Find find( sub {print "I have found $File::Find::name\n" if /\.pl$/;}, "/path/to/dir");
Hope you find this useful.
Cheers,
Paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: file globbing in a nested while loop
by George_Sherston (Vicar) on Oct 05, 2001 at 17:02 UTC | |
by busunsl (Vicar) on Oct 05, 2001 at 17:08 UTC | |
by tommyw (Hermit) on Oct 05, 2001 at 17:53 UTC |