Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Using File::Find

by arnaud99 (Beadle)
on Feb 28, 2013 at 08:52 UTC ( #1021020=note: print w/ replies, xml ) Need Help??


in reply to Re: Using File::Find
in thread Using File::Find

Hi

Another option, and possibly a simpler one for someone new to perl is to use File::Find::Rule. The example below searches through the current directory and its subdirectories, for all files with a .pl extension.

Note that the result is stored in an array, not a hash. The result can be stored in a hash if the user needs to, but the key/value construct would need to be understood eg, is the key the path, and the value the file name, or is the key the full file name and the value the size of the file (or other attributes) etc....

use strict; use warnings; use autodie; use File::Find::Rule; my @txt_files = File::Find::Rule ->file ->name('*.pl') ->in('./'); foreach (@txt_files) { print "$_\n"; }

I hope this helps

Arnaud.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2016-07-01 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (408 votes). Check out past polls.