in reply to subroutine prototype in Perl

See the recent thread USAGE OF Prototype for further discussion and some examples of why prototypes might make your life miserable. You may expect that prototypes will help prevent bugs, but unless you know exactly what you are doing and why, prototypes can actually create more bugs than they prevent.

If you still want to use prototypes after you have read that thread and moritz's links above, perlsub has a description of the prototype syntax and some examples.

Best, beth

Replies are listed 'Best First'.
Re^2: subroutine prototype in Perl
by AnomalousMonk (Archbishop) on Aug 07, 2009 at 18:52 UTC
    As an example of the misery you may expect if you approach Perl prototypes with the mindset of a C or C++ programmer, consider the code below and see if you can explain what is happening – and then imagine it is embedded in the middle of thousands of lines of code. Note that the code has no errors and throws no warnings.

    >perl -wMstrict -le "sub S ($$) { my ($scalar, @array) = @_; return $scalar + $array[0]; } my @ra = (9, 8, 7, 6); print S(3, @ra); " 7