Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: array manipulation

by McDarren (Abbot)
on Jun 15, 2009 at 16:20 UTC ( #771707=note: print w/replies, xml ) Need Help??

in reply to array manipulation

"I don't know if it is zero based like array indices are or if it is one-based"

Why don't you just try it and see?

my @foo = qw/1 2 3 4 5 6/; print "Index 1 is $foo[1]\n";
Do that, and it should be obvious :)

Update: duh, that was a really poor example, given that your question is about splice. Here is a better example:

my @foo = qw/1 2 3 4 5 6/; my @bar = splice @foo, 1,2; print "Indexes 1 & 2 are @bar\n";

Replies are listed 'Best First'.
Re^2: array manipulation
by Transient (Hermit) on Jun 15, 2009 at 16:24 UTC
    I think biohisham means the index used in the offset for the splice function. But similarly,
    perl -le 'my @arr = qw/1 2 3/; print "Removing ",splice(@arr,1,1), "\n +"; print join(" - ", @arr), "\n"'
    Does show you that it is indeed 0-based (by default).

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2016-10-22 17:34 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (297 votes). Check out past polls.