Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Don't ask to ask, just ask
 
PerlMonks  

Calling subroutine syntax

by crabbdean (Pilgrim)
on May 01, 2004 at 14:25 UTC ( #349613=perlquestion: print w/ replies, xml ) Need Help??
crabbdean has asked for the wisdom of the Perl Monks concerning the following question:

I was reading through some module code the other day and I remember seeing a subroutine where it was called like:
sub dothis ($:$$$) { ## rest of the code }
I've seen in other languages (like vb I think) where subroutines are called in such a manner, whereas in perl its generally done like
sub dothis { my ($this, $that) = @_; ## rest of the code }
Does anyone know what this $:$$$ means in Perl?

Dean
The Funkster of Mirth
Programming these days takes more than a lone avenger with a compiler. - sam
RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers

Comment on Calling subroutine syntax
Select or Download Code
Re: Calling subroutine syntax
by zentara (Archbishop) on May 01, 2004 at 14:30 UTC
    Prototyping?
    #!/usr/bin/perl #can use prototype to get around passing hashrefs to subs my_sub(%hash) #prototype for my_sub sub my_sub(\%) { my $hash_ref = shift; map { print "$_ => $$hash_ref{$_} \n" } keys %$hash_ref; }

    I'm not really a human, but I play one on earth. flash japh
      You need to define the prototype before you can use the function.
      sub my_sub (\%) { ... } my_sub(%hash);
      Or if you want to define your function later:
      sub my_sub (\%); my_sub(%hash); sub my_sub (\%) { ... }
      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
Re: Calling subroutine syntax
by dave_the_m (Parson) on May 01, 2004 at 14:40 UTC
    See the section titled 'Prototypes' in the perlsub man page for more details on this.
Re: Calling subroutine syntax
by EdwardG (Vicar) on May 01, 2004 at 14:48 UTC
    Does anyone know what this $:$$$ means in Perl?

    Yes, it is a syntax error.

    use strict; use warnings; sub dothis ($:$$$) { ## rest of the code } __END__ Illegal character in prototype for main::dothis : $:$$$ at d:\tmp\test +.pl line 3
Re: Calling subroutine syntax
by crabbdean (Pilgrim) on May 01, 2004 at 15:13 UTC
    Okay, that answers what it is I saw ... it was prototyping. I'd never seen it before and couldn't find any reference documentation for it because I didn't know what it was called. Thanks. :-)

    Note: My initial example contained a colon (:) in the prototype when really it should have been a semi-colon (;)

    Dean
    The Funkster of Mirth
    Programming these days takes more than a lone avenger with a compiler. - sam
    RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers
      I can recommend Tom Christiansens' rant against prototyping on why in general you want to stay away from it, even though the article is about 5 years old now.

      FMTEYEWTK on Prototypes in Perl

      It used to be available as an article on perl.com too, but not any more.

Re: Calling subroutine syntax
by TomDLux (Vicar) on May 01, 2004 at 19:52 UTC

    Prototyping is of less value than you would expect; It's been discussed, so searching on prototype will show the reasons.

    Prototyping IS sometimes of value if you want a routine to act like a built-in, automatically referencing hashes or arrays to modify them, or declaring a routine to take no arguments. It is totally incompatible with objects, unfortunnately.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

      I had a quick read through the perldoc man page for it and was thinking similar things. My thoughts at the time were "I'll have to come back and have a thorough read through this because I'm not seeing a great use of it right now".

      Dean
      The Funkster of Mirth
      Programming these days takes more than a lone avenger with a compiler. - sam
      RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers
        As TomDLux alluded to above, the only real point is to simulate perl "builtins". For example a grep replacement would look like sub map2(&@) (as I recall) and let you do stuff like  map2 { foo bar } @baz

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://349613]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2014-04-17 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (443 votes), past polls