LNEDAD has asked for the wisdom of the Perl Monks concerning the following question:
When using map to iterate over an array it appears that the elements that which are process are the same no matter how the array is changed during the map operation. Is this always going to be the case with map? On every system? See example code below.
I am writing a script to interact with a vendor program. I have the need to take an array of files and directories, iterate over the elements, and 1. add files to the array so that they are NOT "processed" by map and 2 add directories to the array to be "processed". The process step takes a directory, calls a program given by the vendor and returns a list of files and directories. I know this process should like recursion but given a directory it should take on call to the vendors program to get all the desired files that I need in my final output.
The result will be an array of files. Should I use something other than map to get my desired result.
Code: my @a = ( a1, a2, a3, a4, a5, ); map(&process, @a); print join " ",@a; sub process { push(@a,"x");; unshift(@a,"y");; print "array has " . scalar @a . " elements. This one is " ."====$_\n" +; } Output: array has 7 elements. This one is ====a1 array has 9 elements. This one is ====a2 array has 11 elements. This one is ====a3 array has 13 elements. This one is ====a4 array has 15 elements. This one is ====a5 y y y y y a1 a2 a3 a4 a5 x x x x x
|
|---|