Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2014-08-21 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (139 votes), past polls