Help for this page

Select Code to Download


  1. or download this
    sub insert_after_first {
        my ($ndx, $arr, $elt, $ins) = (0, @_);
        $ndx > @$arr and return while $arr->[$ndx++] ne $elt;
        splice @$arr, $ndx, 0, $ins;
    }
    
  2. or download this
    sub insert_after_first {
        my ($ndx, $arr, $elt, $ins) = (0, @_);
        $arr->[$ndx++] eq $elt and last for 0 .. @$arr;
        splice @$arr, $ndx, 0, $ins if $ndx <= @$arr;
    }