Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: file globbing in a nested while loop

by pjf (Curate)
on Oct 05, 2001 at 16:44 UTC ( [id://116975]=note: print w/replies, xml ) Need Help??


in reply to file globbing in a nested while loop

G'day George,

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.

use File::Find; find(\&printer, "/path/to/dir"); sub printer { print "I have found $File::Find::name\n" if /\.pl$/; }
If you don't like to specify the sub-routine seperately, you can do it with an anonymous subroutine.
use File::Find find( sub {print "I have found $File::Find::name\n" if /\.pl$/;}, "/path/to/dir");
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.

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
    Thanks, and ditto to busunsl. That's certainly solved the problem - I can write my script now, and have re-learnt the ever valuable lesson that time spent researching CPAN is rarely time wasted. But I'd still be very interested if anyone can shed light on why my own attempt didn't work. Is the while loop not restarting? And if so why not?

    § George Sherston
      If this runs on Unix, it might be you are hitting the '.' directory.

      You would be looping on that till eternity.

        Normal globbing doesn't return the dot files.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://116975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-20 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found