Matt wrote:
Thanks Martin,
change following line:
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ &&
/^DATA.*\.zip\z/s && print("$name\n");
to
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ &&
/^DATA.*\.zip\z/s && push @files, $name;
at the end you have all files in the @files array.
I did that, and then at the bottom of the script I tried looping through
just to verify that @files was populated - no dice.
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
$smallcuid = lc $cuid;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted},
'/home/ftpuser/'.$smallcuid.'/flexvault/'.$directory.'/');
exit;
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ &&
/^DATA.*\.zip\z/s && push @files, name;
}
for $element (@files) {
print $element, "\n";
}
What have I done wrong? Although if I put that for loop within the
function it does populate, but it repeats each results 6 times.
It's not displaying the contents of the array becuase you have a
call to exit before the loop.
It's repeating several times because your wanted() subroutine is called
for every file and directory.
The code you have published will put 'name' into @files several times,
and doesn't show the origin of $cuid or directory.
Something like the code below should work.
HTH,
Rob
use strict;
use warnings;
use File::Find;
my ($cuid, $smallcuid);
my $directory;
my @files;
find(\&wanted, "/home/ftpuser/$smallcuid/flexvault/$directory/");
print "$_\n" foreach @files;
sub wanted {
push @files, $File::Find::name if -f and /^DATA.*\.zip\z/s;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/