in reply to Do the Splice Docs on Length Need Tweak?

The doc looks clear enough to me, but maybe it's because I already knew splice's behaviour. Were you expecting something else instead? Like zero being equivalent to an omitted length, where everything until the end is removed?

The unshift example does show explicitly that a length of 0 removes nothing, but it requires understanding unshift, which is not beginner friendly. Maybe the examples list could include an insertion and removal, which is would be more helpful than things that can be done using more specific functions.

Edit: I realized that while the case where LENGTH is omitted or negative are explicitly described, the case where it's positive is only implied because of the name of the parameter. So, rather than the specific case of zero, "If LENGTH is positive (or zero), LENGTH elements are removed".

  • Comment on Re: Do the Splice Docs on Length Need Tweak?

Replies are listed 'Best First'.
Re^2: Do the Splice Docs on Length Need Tweak?
by QM (Parson) on Apr 30, 2019 at 08:04 UTC
    As usual when I post, what's obvious to me doesn't get written down. :/

    I should have added:

    Here's my use case:
    splice(@array, 7, 0, qw(stuff I want to insert));

    So if I want to insert something, but not remove anything, I need a length of zero.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of