in reply to split an array in two

This is my code. Less var changes, more eficient (?)...
sub split_array_in_two { my $len = int($#_/2); return unless ( @_ ); return [ @x[0..$len] ], [ @x[$len+1..$#x] ]; }
scalar(@_) is numbered from 1 to elements... and
$#_ is numbered from 0 to limit.

Your code isnīt long... is readable and suficient.

Replies are listed 'Best First'.
Re^2: split an array in two
by salva (Canon) on Apr 28, 2005 at 09:38 UTC
    scalar(@_) is numbered from 1 to elements... and $#_ is numbered from 0 to limit.

    What do you mean? when @x is empty scalar(@x) is 0 and $#x is -1.