|laziness, impatience, and hubris|
Re: Subroutine's behaviorby tford (Beadle)
|on Nov 23, 2009 at 01:38 UTC||Need Help??|
The reply above mine pretty much says it all. However, you might be wondering what the shift is for.
The shift function takes an array as input, and "shifts" off the first element of the array. Then it returns that element, leaving the array one element shorter.
Now, if you don't specify an array to use as input, the shift function works on the "default array" called @_.
The last important thing to know is that anytime you call a Perl subroutine, you only ever call it with a flat array of arguments. Within the scope of the subroutine, those arguments are automatically assigned to the @_ array.
Thus shift shifts the first argument off the argument array, and assigns it's value to the variable $word, which is local to the subroutine.
Hope this helps!