Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Trouble with File::Find::Rule

by tbone654 (Beadle)
on Dec 13, 2013 at 02:15 UTC ( #1066945=note: print w/ replies, xml ) Need Help??


in reply to Re: Trouble with File::Find::Rule
in thread Trouble with File::Find::Rule

I use this code chunk quite a bit to get directory contents without extra modules, and the nice thing is you only change one line to re-direct to another location, or you use a variable that you pass to it...


This particular version sorts the list and reads the contents of the files into an array, if that is of any value. The array dots is a list of all the files in the directory that you can grep for a pattern and work with.

$sd = "../data"; opendir( DIR, $sd) || die; while( ($filename = readdir(DIR))){ next if "$sd\/$filename" =~ /\/\./; push @dots, "$sd\/$filename"; } ## end of while @dots = sort @dots; closedir(DIR); for($a=0;$a<@dots;$a++){ open (FILE, $dots[$a]); push @foo, <FILE>; close FILE; } ## end of for


Comment on Re^2: Trouble with File::Find::Rule
Download Code
Re^3: Trouble with File::Find::Rule
by sowais (Sexton) on Dec 13, 2013 at 17:06 UTC
    tbone654, thanks for the code! I have used something similar in the past as well but in this case I need to go into all the subfolders of the root folder, thats why I was using File::Find::Rule.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-12-29 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls