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

In reply to Unshift and push inside of map operation. by LNEDAD

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.