in reply to Re^5: split an array in two
in thread split an array in two

I am not quite sure that @_ is so bad ...
sub _split{ @_ == 1 and $#_++; [@_[0..@_/2-1]], [@_[@_/2..@_-1]] } __STDOUT__ <><> <1><> <1><2> <1><2 3> <1 2><3 4> <1 2><3 4 5>


Replies are listed 'Best First'.
Re^7: split an array in two
by Roy Johnson (Monsignor) on Apr 28, 2005 at 16:03 UTC
    Apart from the fact that you're still not getting the OP's results, and you now (merely) generate a warning for the 1-element case, you're going through some rather silly gyrations to use @_ as an index instead of $#_. Using @_ as an index is still a bad idea, like using a screwdriver as a hammer. You might eventually get the result you want, but it's needlessly difficult.

    Caution: Contents may have been coded under pressure.
      ..needlessly difficult?..

      The Python rule - "There should be one--
      and preferably only one --obvious way to do it."?
      No, I program in Perl.'difficult||easy' - meaningless words.
      Never-the-less - thanks for being polite!