In this specific case, I would probably go for a single map such as the solution proposed by linuxer. However, building on your own solution, I would like to point out that you don't need an intermediary array @ind if you just pipeline the grep and the map, as shown in the following Perl debugger session:

DB<1> @a = ( 6,7,8 ); DB<2> @b = ( 3,2,1 ); DB<3> @c = map {$a[$_]} grep {$b[$_] > 1} 0..$#b; DB<4> p "@c"; 6 7 DB<5>
Again, in this specific case, I would probably do everything in one map, as in the solution proposed by linuxer, but the possibility of pipelining various list operators as above can be a very powerful tool. This is an example of the same idea on the same problem, using two more list operators:
DB<5> print join " ; ", map {$a[$_]} grep {$b[$_] > 1} 0..$#b; 6 ; 7 DB<6>
To understand this type of command pipeline, it has to be read from right to left ( and from bottom to top if it is spread on several lines). Well known examples of such constructs are the Schwartzian Transform and variations thereon such as the Guttman-Rosler Transform for efficiently sorting data.

Update: When I started to type this, there was only linuxer's answer. Then, while I was typing the above, my daughter came twice to ask me something, so that it took me 20 or 25 minutes to finish typing the above, and many good answers were delivered in between, so that the above is less useful. Alright, fair enough, you have to be fast if you want to be the first. ;-)


In reply to Re: Boolean array indexing by Laurent_R
in thread Boolean array indexing by johnmillerflorida

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.