in reply to sub many asterisk semicolon separated
Hello AlienResidents, and welcome to the Monastery!
As LanX and GrandFather have explained, the given prototype has the effect of requiring one argument and allowing up to 82 additional arguments.
But it has another effect: it coerces each argument into scalar context. To demonstrate this, here is a script which takes advantage of the fact that calling a subroutine with an initial ampersand — &name(...) — disables the prototype for that function call. So does calling the subroutine via a reference:
#! perl use strict; use warnings; sub name(*;**) { printf "First argument: %s\n" . "Second argument: %s\n" . "Third argument: %s\n\n", @_; } printf "\nname() has prototype (%s)\n\n", prototype('name'); my @array = ('foo', 'bar'); &name('1a', 'u', 'v'); name('1b', 'u', 'v'); &name('2a', ('x', 'y')); name('2b', ('x', 'y')); &name('3a', @array, 'extra_1'); name('3b', @array, 'extra_2'); my $fp = \&name; $fp->('3c', @array, 'extra_3');
Output:
16:19 >perl 833_SoPW.pl Useless use of a constant ("x") in void context at 833_SoPW.pl line 29 +. name() has prototype (*;**) First argument: 1a Second argument: u Third argument: v First argument: 1b Second argument: u Third argument: v First argument: 2a Second argument: x Third argument: y Missing argument in printf at 833_SoPW.pl line 19. First argument: 2b Second argument: y Third argument: First argument: 3a Second argument: foo Third argument: bar First argument: 3b Second argument: 2 Third argument: extra_2 First argument: 3c Second argument: foo Third argument: bar 16:19 >
See Far More than Everything You've Ever Wanted to Know about Prototypes in Perl -- by Tom Christiansen.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|