Help for this page

Select Code to Download


  1. or download this
    my ($rank) = grep {$sorted_array[$_] eq $my_target} 0..$#sorted_array;
    
  2. or download this
    sub index_of {
      my $thing = shift;
      my @indexes = grep $_[$_] eq $thing, 0..$#_;
      wantarray ? @indexes : $indexes[0];
    }
    
  3. or download this
    my $rank = index_of($my_target, @sorted_array);
    
  4. or download this
    my %sorted_index;
    $sorted_index{$sorted_array[$_]} = $_ foreach 0..$#sorted_array;
    
  5. or download this
    my %sorted_index = map {($_, $sorted_array[$_])} 0..$#sorted_array;
    
  6. or download this
    my @doubled = map {($_, $_)} 1..50_000;
    
  7. or download this
    my %sorted_index;
    @sorted_index{@sorted_array} = 0..$#sorted_array;