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("..");
In reply to Recursive file search by mellin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |