http://www.perlmonks.org?node_id=773937


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

I suppose the "technical reason" is that it's something we inherited from C. And in C, an array index is actually an offset from the start of the array. The first element is therefore at index zero as it's offset zero elements from the start of the array.

There's no real technical reason why it should still be implemented that way. But generations of programmers expect it to work like that.

Update: Please do not be tempted to use $[ to change the index base. Really, don't do it. Just forget it exists. If you use it you'll just create a maintenance nightmare for the people who look after your program after you.

--

See the Copyright notice on my home node.

Perl training courses

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

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.