Help for this page

Select Code to Download


  1. or download this
    my @filtered = grep { condition($_) } @elements;
    
  2. or download this
    my @indexes = grep { condition($elements[$_]) } 0..$#elements;
    
  3. or download this
    my @filtered;
    for (@elements) {  # Not any list, an array specifically.
       push @filtered, $_ if condition($_);
    }
    
  4. or download this
    my @indexes;
    for (0..$#elements) {
       push @indexes, $_ if condition($elements[$_]);
    }