Help for this page

Select Code to Download


  1. or download this
    sub insert_after_first {
       my ($arr, $find, $insert) = @_;
    ...
       my ($pos) = grep { $arr->[$_] eq $find and !$found++ } 0..$#$arr;
       splice @$arr, $pos+1, 0, $insert if $found;
    }
    
  2. or download this
    sub insert_after_first {
       my ($arr, $find, $insert) = @_;
       my ($pos) = grep { $arr->[$_] eq $find } 0..$#$arr;
       splice @$arr, $pos+1, 0, $insert if defined($pos);
    }