mellin has asked for the wisdom of the Perl Monks concerning the following question:
So directory 'archive' has subdirs based on years and they have subdirs based on months, latter ones then have these xml-files that i would like to read on to array. When the funtion has read recursively all subdirs and pushed xml-files to array, it then returns that array. Where i'm facing problem, is with this code that i've copied from web and modified to suit my needs:archive .2005 ..12 ...420.xml ..11 ...419.xml ..10 ...418.xml ...417.xml .2004 ..9 ...416.xml ..7 ...415.xml .2003 ..5 ...414.xml ..4 ...413.xml ..2 ...412.xml
There doesn't seem to be any other way to introduce that '@files' array, other than higher in the program. I would like this loopDir function to return it, not modify elsewhere introduced array. Like this i mean: my @files = loopDir('./');#!/usr/bin/perl my @files; loopDir('./'); print "found xml-files $#files..\n"; sub loopDir { local ($dir) = @_; chdir $dir or die "Cannot chdir to $dir\n"; local(*DIR); opendir DIR, '.'; while ($f=readdir(DIR)) { next if $f =~ /^\./; push @files, $dir . '/' . $f if $f =~ /.*\.xml$/; if (-d $f) { &loopDir($f); } } closedir(DIR); chdir("..");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recursive file search
by Corion (Patriarch) on Feb 20, 2005 at 01:04 UTC | |
|
Re: Recursive file search
by blahblahblah (Priest) on Feb 20, 2005 at 03:51 UTC | |
by merlyn (Sage) on Feb 20, 2005 at 04:24 UTC | |
by mellin (Scribe) on Feb 20, 2005 at 10:09 UTC | |
|
Re: Recursive file search
by Miguel (Friar) on Feb 20, 2005 at 15:34 UTC | |
|
Re: Recursive file search
by sh1tn (Priest) on Feb 20, 2005 at 22:52 UTC |