in reply to Subroutine's behavior
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.
For example,
my @array = (2,3,4); my $value = shift(@array); # now the array contains (3,4) print "value is $value";
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!
~tford
|
|---|