Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Do the Splice Docs on Length Need Tweak?

by Eily (Monsignor)
on Apr 29, 2019 at 13:55 UTC ( [id://1233122]=note: print w/replies, xml ) Need Help??


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".

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1233122]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found