Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by cosmicperl (Chaplain)
on Oct 13, 2007 at 02:47 UTC ( [id://644590]=perlquestion: print w/replies, xml ) Need Help??

cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
  Ok, this has been bugging me for ages and I still haven't read or found anything to describe it. I've seen a few sub routines that have what looks like variable markers after them, today I came by the most complicated of which I've seen so far.
sub Request(;***$*$) {
I'm guessing this has something to do with the variables that are passed in?? But this example has a ;?? Eh? Can someone please give me a good explanation/description, or point me to the right docs.

Thanks

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

Replies are listed 'Best First'.
Re: Sub routine ??? (This has been bugging me for ages)
by Somni (Friar) on Oct 13, 2007 at 02:53 UTC
    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.

      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.
Re: Sub routine ??? (This has been bugging me for ages)
by throop (Chaplain) on Oct 13, 2007 at 05:12 UTC
    Your code contains prototypes. These allow
    • function calls to be written with fewer parentheses, in some cases, and with a strong possibility of a loss of readability.
    • function calls with fewer backslashes.
      Using prototypes force you to explicitly write each param instead of passing list containing correct params to subroutine... :-(

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://644590]
Approved by tye
Front-paged by friedo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-07-18 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.