in reply to Re: perl5 "prototyping": why?
in thread perl5 "prototyping": why?

Thanks, I was thinking the same thing. But what if the arguments are complex?
sub foo (\$\@\%) { my ( $bar, @baz, %something ) = @_; }
...erm, I'm just making up that example (obviously), and I never bother with prototypes so this may well be all wrong, but wouldn't @baz suck in the remainder of @_ after $bar if you remove the prototype? Or something like that?

Replies are listed 'Best First'.
Re^3: perl5 "prototyping": why?
by CountZero (Bishop) on Jul 07, 2005 at 21:19 UTC
    Perldoc says:
    Any backslashed prototype character represents an actual argument that absolutely must start with that character. The value passed as part of @_ will be a reference to the actual argument given in the subroutine call, obtained by applying \ to that argument.
    So you call foo as foo($a_scalar, @an_array, %a_hash) and you will get automatic reference/dereference magic.

    Dropping the backslash however breaks this behaviour:

    Unbackslashed prototype characters have special meanings. Any unbackslashed @ or % eats all remaining arguments, and forces list context. An argument represented by $ forces scalar context.

    @baz would then indeed gobble up the hash following it.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law