Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: The purpose of prototypes in perl subroutines

by jjhorner (Hermit)
on Apr 13, 2005 at 15:13 UTC ( #447449=note: print w/replies, xml ) Need Help??

in reply to The purpose of prototypes in perl subroutines

Prototyping has a use when running with the strict 'subs' pragma. While it is in effect, you will have to prototype your subs to use the bareword style when calling:
sub mysub; print mysub;
or, use the ampersand or parens:
print mysub();
*** Special thanks to Nat Torkington. I've been reading Jon Orwant's Computer Science and Perl Programming book lately. Good information, and a good review of perl topics you may have forgotten. Pick it up if you don't have it.
J. J. Horner 

Replies are listed 'Best First'.
Re^2: The purpose of prototypes in perl subroutines
by Joost (Canon) on Apr 13, 2005 at 15:31 UTC
    That's not prototyping: that's just predeclaring that the subroutine mysub exists. You're explicitly not specifying a prototype there.

    You can call any subroutine without parentheses as long as it's been "seen" before:

    #!/usr/local/bin/perl -w use strict; sub bla { print "Bla!\n"; } bla;
    update: Ironically, a nice way to make the above fail is to use a (wrong) protoype:
    #!/usr/local/bin/perl -w use strict; sub bla($) { print "Bla!\n"; } bla; __END__ syntax error at line 8, near "bla;" Execution of aborted due to compilation errors.
      It is the same thing. Ask Nat Torkington, as that is what he calls it. Probably pure semantics, but either way, it is considered prototyping.
      J. J. Horner 

        Just because someone says something doesn't make it true. This isn't just semantics, either.

        Perhaps you give us the reference where you found Nat talking about this sort of prototype (article name or page number would work). IF you are talking about the "Cryptocontext" article, I think you've misunderstood something.

        brian d foy <>

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2023-06-06 09:28 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (26 votes). Check out past polls.