Foggy Bottoms has asked for the wisdom of the Perl Monks concerning the following question:
Dearest monks of far and wide,
As you may know when one writes a sub, he/she can send parameters to that sub and one of the most convenient ways to retrieve those parameters is by using the tool shift...
One question has been puzzling me however... Let's take for example the following sub :
Surely this is a trivial question and I'm probably overlooking something important - but I'm still quite intrigued. Could someone please enlighten me ?
As you may know when one writes a sub, he/she can send parameters to that sub and one of the most convenient ways to retrieve those parameters is by using the tool shift...
One question has been puzzling me however... Let's take for example the following sub :
How does the sub manage to figure out what's the size of @a and @b so that when you use the shift tool you don't end up with @array1 being ("mary","had","a","little","lamb","!","London","Bridge","is"); and @array2 nothing...sub test { my $number = shift; my @array1 = shift; my @array2 = shift; # do your stuff } ........................ my @a = ("mary","had","a","little","lamb","!"); my @b = ("London","Bridge","is"); # call sub test(3,@a,@b);
Surely this is a trivial question and I'm probably overlooking something important - but I'm still quite intrigued. Could someone please enlighten me ?
Back to
Seekers of Perl Wisdom