I want to make functions that look like the built-in ones. The answer is to use function prototypes. They are a brief note to Perl to tell it how to treat the arguments it gets. Sending the function a list of values will result in Perl whining at you that the function has gotten too many arguments, but sending it an array will return the number of elements in the array. This works as expected, which is A Good Thing.
Examples Let's make the functions shown at the beginning of the article.
This variable is used to hold the current index to be used in the array lookups. As a default, this function will only go through the arrays as many times as the shorter array has elements. When it is to stop, it resets all its private variables, and returns nothing, which evaluates as false in scalar context, and an empty list in list context. This function is a good introduction to closures , to be explained in a future article. Closures are a way of using private data that remains in existence after it appears to go out of scope.