in reply to split an array in two

Splice:

sub split_array_in_two { my @x = @_; my @second = splice @x, @x/2; \@x, \@second; }
Explicitly returning empty array references is unnecessary, since an empty argument list will give you that anyway.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: split an array in two
by Roy Johnson (Monsignor) on Apr 28, 2005 at 15:09 UTC
    Note that your solution divides the data differently than the OP's code. Use 1+$#x/2 instead of @x/2 to get the OP's result.

    You can also write it

    sub split_array_in_two{ \@_, [splice @_, 1+$#_/2] }

    Caution: Contents may have been coded under pressure.