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,


In reply to Re: sub many asterisk semicolon separated by Athanasius
in thread sub many asterisk semicolon separated by AlienResidents

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.