in reply to Boolean array indexing
If your arrays are small go with one of the many grep/map/slice answers offered, but be aware that for large arrays they will create two or more huge intermediate lists that consume substantial amounts of memory, and thus time.
The alternative that avoids those huge stack allocations only requires a single temporary scalar and runs very efficiently:
@a=(6,7,8); @b=(3,2,1);; $i=0; $b[$_] > 1 and $c[ $i++ ] = $a[$_] for 0 .. $#a;; print @c;; 6 7
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Boolean array indexing
by Anonymous Monk on Nov 22, 2013 at 07:11 UTC | |
by BrowserUk (Patriarch) on Nov 22, 2013 at 08:33 UTC |