Did older versions of Perl have different rules for indexing arrays?

I am currently working on translating Perl code written in 1996/8 to Python. I'm just curious. Current Perl seems to have 0-based indexing for arrays (i.e. the first element would be:

Array1[0]

      

and the last element will be

Array1[$#Array1-1]   

      

(I think ... understand Perl better than write)
Was just wondering if the early versions had the first like

Array1[1]

      

and the last one - how

Array1[$#Array1]

      

Just wondering if this changed at some point in development?
This may be my own stupidity, in which case I just need to better understand my understanding of the program, but if anyone can point me to which one, I would appreciate it.

thank

+3


source to share


1 answer


No, the first element is always $Array1[0]

, and the last one is $Array1[$#Array1]

either $Array1[-1]

or$Array1[@Array1 -1]

Exception for first element - only when changing the default $[



This variable stores the index of the first element in the array and the first character in the substring. The default is 0, but in theory you could set it to 1 to make Perl behave like awk (or Fortran) when signing and evaluating the index () and substr () functions.

.. Mnemonic: [starts indexes. Deprecated in Perl v5.12.0.

+11


source







All Articles