in reply to split an array in two

You don't need to copy the array; creating an arrayref does that. And you can calculate the indices on the fly, so you need no temp variables or calls to splice. Just one expression:
sub split_array_in_two { ([@_[0..$#_/2]], [@_[$#_/2+1..$#_]]); } for (0..5) { print map("<@$_>", split_array_in_two(1..$_)), "\n"; }

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: split an array in two
by Anonymous Monk on Apr 28, 2005 at 14:43 UTC
    sub split_array_in_two{ [@_[0..@_/2-1]], [@_[@_/2..@_]] }
      You're reaching beyond the end of the array, resulting in an extra undef getting stuck on the end of your second arrayref. Also, a one element list gets replicated in both resulting arrays.

      Caution: Contents may have been coded under pressure.
        #must be: [@_[0..@_/2-1]], [@_[@_/2..@_-1]]