|
|
|
good chemistry is complicated, and a little bit messy -LW |
|
| PerlMonks |
Re: why the array index has to start at 0??by davorg (Chancellor) |
| on Jun 23, 2009 at 10:10 UTC ( #773937=note: print w/ replies, xml ) | Need Help?? |
|
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.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||