Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
XP is just a number
 
PerlMonks  

Re: Prototype question

by CountZero (Chancellor)
on Sep 05, 2012 at 12:41 UTC ( #991827=note: print w/ replies, xml ) Need Help??


in reply to Prototype question

Just forget about prototypes. Perl does not need them in most cases. All agree that the Perl prototypes are one of the most misunderstood features of Perl. More specifically they are NOT made to give you the general ability to check whether correct paramaters have been provided to your sub. If you want to make sure correct parameters are given to your sub, you must include these tests inside your sub and these tests then work at run-time, not at compile-time (as in many bondage and discipline languages).

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics


Comment on Re: Prototype question
Re^2: Prototype question
by rovf (Priest) on Sep 05, 2012 at 12:54 UTC
    I know; however, if you want to use the "code block" syntax to call a function, you must define a prototype. At least Perl 5.8.8 (which I still have to use) does not provide an alternative.

    My solution to my original problem was to use a cover function. Basically I define my function f without prototypes, and then add a function

    sub g(&@) { &f }
    to provide the ability to write codeblocks.

    -- 
    Ronald Fischer <ynnor@mm.st>
      Indeed you are right. I somehow missed the "code block" reference in your post or misread it as a anonymous sub reference. Sorry for that.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2014-04-18 21:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (472 votes), past polls