in reply to Sub routine ??? (This has been bugging me for ages)

Those are prototypes, documented in perlsub. They are used reduce code clutter and mimic the behavior of builtins by changing how the compiler parses subroutine calls.

Most Perl programmers new to prototypes instantly assume they're like other languages' prototypes, i.e. they are for declaring how many and what type of parameters a function expects. This is a misuse of them, as it generally causes problems and is quite often bypassed entirely anyways. See FMTEYEWTK about Prototypes. The article was long ago removed from O'Reilly's site, but it still remains relevant.

  • Comment on Re: Sub routine ??? (This has been bugging me for ages)

Replies are listed 'Best First'.
Re^2: Sub routine ??? (This has been bugging me for ages)
by Krambambuli (Curate) on Oct 13, 2007 at 10:30 UTC
    If Tom Christiansen's article indicated above hasn't convinced you, there is a somewhat shortened form of what it is saying in Damian Conway's "Perl Best Practices":

    Don't use subroutine prototypes

    Now, if that isn't clear enough.. :)

    Chapter 9 of the PBP book, "Subroutines", has a section "9.10 Prototypes"; I think the book in it's entirety is worthwhile reading (actually, having it handy) if you enjoy doing things with Perl.

    Good luck with those not-quite-friendly prototypes.