Dear perlmonks,
I am looking for the simplest way (preferrably a one line code) to extract those elements from an array for which certain conditions are true.
I know that this is a very simple question, yet I have been unable to find its answer online which leads me to believe that I probably have been using the wrong terminology.
Below is a simple working example: I have two arrays a=(6,7,8) and b=(3,2,1) and I want only those elements of 'a' for which the elements in 'b' are greater than 1. The code below is working, but seems awfully complicated for such simple a task.
So if you know of a simpler possibility to achieve this, your help is very much appreciated. Thank you!
#!/usr/bin/perl use warnings; use strict; use diagnostics; my @a=(6,7,8); my @b=(3,2,1); my @ind = grep { $b[$_]>1 } 0..$#b; @a= map{ $a[$_]}@ind;
In reply to Boolean array indexing by johnmillerflorida
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |