Is there a less clumsy alternative for copying up to “n” array elements?

前端 未结 5 1126
名媛妹妹
名媛妹妹 2021-01-11 13:57

In a world of many @choices
With a $limit to what one can do,
Life proposes many @options
But at time

5条回答
  •  一整个雨季
    2021-01-11 14:05

    my @choices = first_x_ele($limit, @options);
    

    If you think something is unclear, use a sub! How you implement the sub isn't very important, but a short one would be:

    sub first_x_ele { my $x = shift; splice(@_, 0, $x) }
    

提交回复
热议问题