Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Iterate Recursively Through Directories

by tbone654 (Beadle)
on Feb 11, 2014 at 20:18 UTC ( #1074498=note: print w/replies, xml ) Need Help??


in reply to Re: Iterate Recursively Through Directories
in thread Iterate Recursively Through Directories

I don't know if this helps for anything, this doesn't Iterate Recursively as shown, but I use readdir in the following code to create an array $dots of filenames from a directory, excluding any "." prefix in unix. Then I can grep out anything I don't want to operate on, etc. Or in this case put the contents of all the files into a single array $foo, then grep out or split out whatever I'm looking for. I think it can be modified to do something useful without a module.

$sd = "../data/data_forthis"; 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(my $a=0;$a<@dots;$a++){ open (FILE, $dots[$a]); push @foo, <FILE>; if ($a+1 eq @dots) { close FILE; open (FILE, $dots[$a]); push @foo2, <FILE>; } ## end of if close FILE; } ## end of for ### At this point @foo has everything and $foo2 has just the last file + in the directory...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1074498]
help
Chatterbox?
[Tux]: Hmm, that must be something in pm_cb_g
[Tux]: in the dialog area it shows correct, but the url is broken in the CB
[Discipulus]: you still need to put href:// , no?
[Tux]: [htps://metacpan. org/source/ MLEHMANN/Canary- Stability-2012/ Stability.pm#L124| this] is the same link posted on the PM side inside the CB
[Discipulus]: and you wrote ttps and then htps
[Tux]: new try
[Tux]: \o/ (sorry for the noise)
[Discipulus]: anyway, i'm more interested about the general idea: you (and others) do not install modules by this guy. Rigth?
[Tux]: correct
[Tux]: and I know about companies that blocked him for legal reasons. His inability to fix issues (or his tendency to reject/delete issues if he doesn't like them) makes companies block his stuff. They require support

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-09-20 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (234 votes). Check out past polls.

    Notices?