Help for this page

Select Code to Download


  1. or download this
    use List::Util 'first';
    my $first_index = first { test( $arr[ $_ ] ) } 0..$#arr;
    
  2. or download this
    my $first_index = first { $arr[ $_ ] =~ /$pat/ } 0..$#arr;
    
  3. or download this
    my $first_index = ( grep test( $arr [$_ ] ), 0..$#arr )[ 0 ];