It assigns zero to the first element of the array. To set an array to an empty list, use:

Code

@array = ();

To set the length of an array to any non-zero value, set the last element to an arbitrary value.

Congratulations for using lexical variables. However declaring all of them at the beginning of your file largely defeats their value. You should declare each variable in the smallest possible scope. Always use strict and warnings.

Update: I have noticed another likely error. You return a zero for index if the zero-th element matches or if there is no match at all. I recommend using the last_index routine in the module List::MoreUtils. (It returns -1 for no-match) Good Luck, Bill