Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: why the array index has to start at 0??

by YuckFoo (Abbot)
on Jun 23, 2009 at 14:24 UTC ( #774038=note: print w/ replies, xml ) Need Help??


in reply to why the array index has to start at 0??

It's works cleanly with so many constructs, like ...

with mod operator, for ring buffers:

$buffer[$i++ % $SIZE] = $foo;
with rand():

$pick = $array[rand(@array)];
I'm sure we could come up with many others. Natural, no?

ZeroFoo


Comment on Re: why the array index has to start at 0??
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2014-10-31 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (216 votes), past polls