in reply to Re^5: File::Find: Return array of "wanted" files
in thread File::Find: Return array of "wanted" files

So, to push to the array with the array inside the foreach block, I would do this:

my @array1; my @array2; foreach (@array1) { undef @array2; find(\&mysub, cwd); ..do stuff with @array2 } sub mysub { my $file = $File::Find::name; ..filter stuff here... push(@array2, $file); }

Or is there a nore elegant way of doing this?

Replies are listed 'Best First'.
Re^7: File::Find: Return array of "wanted" files
by Laurent_R (Canon) on Oct 07, 2013 at 17:05 UTC

    Why do you undef @array2 within your foreach loop? Do you need a fresh xopoty of @array2 each time? Probably not.