Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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";
Comment on Re: array manipulation
Select or Download Code
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 making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2016-05-05 07:58 GMT
Find Nodes?
    Voting Booth?